[deploy] Refactor:Move remove_old_notifications Rake Task to Sidekiq (#9936)
* Refactor:Move remove_old_notifications Rake Task to Sidekiq * fix typo
This commit is contained in:
parent
17df627f0d
commit
e07c707ede
4 changed files with 29 additions and 3 deletions
11
app/workers/notifications/remove_old_notifications_worker.rb
Normal file
11
app/workers/notifications/remove_old_notifications_worker.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Notifications
|
||||
class RemoveOldNotificationsWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :low_priority, retry: 10
|
||||
|
||||
def perform
|
||||
Notification.fast_destroy_old_notifications
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -77,3 +77,6 @@ send_welcome_notifications:
|
|||
send_email_digest:
|
||||
cron: "30 11 * * 3,4,5,6" # 11:30 am UTC Wed, Thurs, Fri, Sat, Sun
|
||||
class: "SendEmailDigestWorker"
|
||||
remove_old_notifications:
|
||||
cron: "0 5 * * *" # daily at 5 am UTC
|
||||
class: "Notifications::RemoveOldNotificationsWorker"
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
task remove_old_notifications: :environment do
|
||||
Notification.fast_destroy_old_notifications
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Notifications::RemoveOldNotificationsWorker, type: :woker do
|
||||
include_examples "#enqueues_on_correct_queue", "low_priority"
|
||||
|
||||
describe "#perform" do
|
||||
let(:worker) { subject }
|
||||
|
||||
it "fast destroys notifications" do
|
||||
allow(Notification).to receive(:fast_destroy_old_notifications)
|
||||
worker.perform
|
||||
expect(Notification).to have_received(:fast_destroy_old_notifications)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue