Refactor:Move Credit Counter Cache Sync to Sidekiq (#9972)
This commit is contained in:
parent
eddcb4953e
commit
513717e680
4 changed files with 29 additions and 4 deletions
11
app/workers/credits/sync_counter_cache.rb
Normal file
11
app/workers/credits/sync_counter_cache.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Credits
|
||||
class SyncCounterCache
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :low_priority, retry: 10
|
||||
|
||||
def perform
|
||||
Credit.counter_culture_fix_counts only: %i[user organization]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -98,3 +98,6 @@ send_email_digest:
|
|||
remove_old_notifications:
|
||||
cron: "0 5 * * *" # daily at 5 am UTC
|
||||
class: "Notifications::RemoveOldNotificationsWorker"
|
||||
sync_credits_counter_cache:
|
||||
cron: "0 16 * * *" # daily at 4 pm UTC
|
||||
class: "Credits::SyncCounterCache"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,3 @@ end
|
|||
task github_repo_fetch_all: :environment do
|
||||
GithubRepo.update_to_latest
|
||||
end
|
||||
|
||||
task fix_credits_count_cache: :environment do
|
||||
Credit.counter_culture_fix_counts only: %i[user organization]
|
||||
end
|
||||
|
|
|
|||
15
spec/workers/credits/sync_counter_cache_spec.rb
Normal file
15
spec/workers/credits/sync_counter_cache_spec.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Credits::SyncCounterCache, type: :woker do
|
||||
include_examples "#enqueues_on_correct_queue", "low_priority"
|
||||
|
||||
describe "#perform" do
|
||||
let(:worker) { subject }
|
||||
|
||||
it "syncs counter cache for credits" do
|
||||
allow(Credit).to receive(:counter_culture_fix_counts)
|
||||
worker.perform
|
||||
expect(Credit).to have_received(:counter_culture_fix_counts).with(only: %i[user organization])
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue