Refactor:Move Credit Counter Cache Sync to Sidekiq (#9972)

This commit is contained in:
Molly Struve 2020-08-24 14:20:11 -05:00 committed by GitHub
parent eddcb4953e
commit 513717e680
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View 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

View file

@ -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"

View file

@ -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

View 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