Move Events::BustCacheJob to Sidekiq and rename (#5379)
This commit is contained in:
parent
3188b37762
commit
bc2dbd8e7f
6 changed files with 27 additions and 30 deletions
|
|
@ -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
|
||||
|
|
@ -45,6 +45,6 @@ class Event < ApplicationRecord
|
|||
end
|
||||
|
||||
def bust_cache
|
||||
Events::BustCacheJob.perform_later
|
||||
Events::BustCacheWorker.perform_async
|
||||
end
|
||||
end
|
||||
|
|
|
|||
10
app/workers/events/bust_cache_worker.rb
Normal file
10
app/workers/events/bust_cache_worker.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
13
spec/workers/events/bust_cache_worker_spec.rb
Normal file
13
spec/workers/events/bust_cache_worker_spec.rb
Normal 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
|
||||
Loading…
Add table
Reference in a new issue