From a9e4265a1a344e60686b13ebf2d8b45be3674ca3 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 20 Jan 2024 14:48:57 +0100 Subject: [PATCH] Add scheduled job to clean up orphaned inbox entries --- app/workers/scheduler/inbox_cleanup_scheduler.rb | 15 +++++++++++++++ config/sidekiq.yml | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 app/workers/scheduler/inbox_cleanup_scheduler.rb diff --git a/app/workers/scheduler/inbox_cleanup_scheduler.rb b/app/workers/scheduler/inbox_cleanup_scheduler.rb new file mode 100644 index 00000000..77948ab0 --- /dev/null +++ b/app/workers/scheduler/inbox_cleanup_scheduler.rb @@ -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 diff --git a/config/sidekiq.yml b/config/sidekiq.yml index b9c163be..b224130a 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -13,4 +13,11 @@ production: - question - export - push_notification + - scheduler +:scheduler: + :schedule: + inbox_cleanup: + every: 1m + class: Scheduler::InboxCleanupScheduler + queue: scheduler