Add scheduled job to clean up orphaned inbox entries

This commit is contained in:
Andreas Nedbal 2024-01-20 14:48:57 +01:00 committed by Andreas Nedbal
parent 66142f9cad
commit a9e4265a1a
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
class Scheduler::InboxCleanupScheduler
include Sidekiq::Worker
sidekiq_options retry: false
def perform
orphaned_entries = Inbox.where(question_id: nil).includes(:user)
orphaned_entries.each do |inbox|
logger.info "Deleting orphaned inbox entry #{inbox.id} from user #{inbox.user.id}"
inbox.destroy
end
end
end

View File

@ -13,4 +13,11 @@ production:
- question
- export
- push_notification
- scheduler
:scheduler:
:schedule:
inbox_cleanup:
every: 1m
class: Scheduler::InboxCleanupScheduler
queue: scheduler