Move Events::BustCacheJob to Sidekiq and rename (#5379)

This commit is contained in:
Molly Struve 2020-01-06 15:51:46 -05:00 committed by GitHub
parent 3188b37762
commit bc2dbd8e7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 30 deletions

View file

@ -1,9 +0,0 @@
module Events
class BustCacheJob < ApplicationJob
queue_as :events_bust_cache
def perform(cache_buster = CacheBuster)
cache_buster.bust_events
end
end
end

View file

@ -45,6 +45,6 @@ class Event < ApplicationRecord
end
def bust_cache
Events::BustCacheJob.perform_later
Events::BustCacheWorker.perform_async
end
end

View file

@ -0,0 +1,10 @@
module Events
class BustCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :low_priority, retry: 10
def perform
CacheBuster.bust_events
end
end
end

View file

@ -1,19 +0,0 @@
require "rails_helper"
RSpec.describe Events::BustCacheJob do
include_examples "#enqueues_job", "events_bust_cache"
describe "#perform_now" do
let(:cache_buster) { class_double(CacheBuster) }
before do
allow(cache_buster).to receive(:bust_events)
end
it "busts cache" do
described_class.perform_now(cache_buster)
expect(cache_buster).to have_received(:bust_events)
end
end
end

View file

@ -26,6 +26,8 @@ RSpec.describe Event, type: :model do
end
it "triggers cache busting on save" do
expect { event.save }.to have_enqueued_job.on_queue("events_bust_cache")
sidekiq_assert_enqueued_jobs(1, queue: "low_priority") do
event.save
end
end
end

View file

@ -0,0 +1,13 @@
require "rails_helper"
RSpec.describe Events::BustCacheWorker do
include_examples "#enqueues_on_correct_queue", "low_priority"
describe "#perform" do
it "busts cache" do
allow(CacheBuster).to receive(:bust_events)
described_class.new.perform
expect(CacheBuster).to have_received(:bust_events)
end
end
end