diff --git a/app/workers/credits/sync_counter_cache.rb b/app/workers/credits/sync_counter_cache.rb new file mode 100644 index 000000000..224283e23 --- /dev/null +++ b/app/workers/credits/sync_counter_cache.rb @@ -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 diff --git a/config/schedule.yml b/config/schedule.yml index 7053648a0..eed479291 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -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" diff --git a/lib/tasks/fetch.rake b/lib/tasks/fetch.rake index 9ad7ddaeb..2c2ade3c1 100644 --- a/lib/tasks/fetch.rake +++ b/lib/tasks/fetch.rake @@ -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 diff --git a/spec/workers/credits/sync_counter_cache_spec.rb b/spec/workers/credits/sync_counter_cache_spec.rb new file mode 100644 index 000000000..23780d5f7 --- /dev/null +++ b/spec/workers/credits/sync_counter_cache_spec.rb @@ -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