Skip to content

Commit

Permalink
Refactor Podcasts Bust Cache job (#5421)
Browse files Browse the repository at this point in the history
  • Loading branch information
maykonmenezes authored and mstruve committed Jan 28, 2020
1 parent 1d701c7 commit 3b3d2be
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
9 changes: 0 additions & 9 deletions app/jobs/podcasts/bust_cache_job.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ def unique_slug_including_users_and_orgs
def bust_cache
return unless path

Podcasts::BustCacheJob.perform_later(path)
Podcasts::BustCacheWorker.perform_async(path)
end
end
11 changes: 11 additions & 0 deletions app/workers/podcasts/bust_cache_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Podcasts
class BustCacheWorker
include Sidekiq::Worker

sidekiq_options queue: :high_priority, retry: 10

def perform(path)
CacheBuster.bust_podcast(path)
end
end
end
18 changes: 0 additions & 18 deletions spec/jobs/podcasts/bust_cache_job_spec.rb

This file was deleted.

11 changes: 4 additions & 7 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,12 @@
end

context "when callbacks are triggered after save" do
let(:page) { build(:page) }

before do
allow(Pages::BustCacheWorker).to receive(:perform_async)
end
let(:page) { create(:page) }

it "triggers cache busting on save" do
page.save
expect(Pages::BustCacheWorker).to have_received(:perform_async).with(page.slug)
sidekiq_assert_enqueued_with(job: Pages::BustCacheWorker, args: [page.slug]) do
page.save
end
end
end
end
4 changes: 3 additions & 1 deletion spec/models/podcast_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

context "when callbacks are triggered after save" do
it "triggers cache busting on save" do
expect { build(:podcast).save }.to have_enqueued_job.on_queue("podcasts_bust_cache").once
sidekiq_assert_enqueued_with(job: Podcasts::BustCacheWorker, args: [podcast.path]) do
podcast.save
end
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/workers/podcasts/bust_cache_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "rails_helper"

RSpec.describe Podcasts::BustCacheWorker, type: :worker do
let(:worker) { subject }

before do
allow(CacheBuster).to receive(:bust_podcast)
end

describe "#perform" do
it "busts cache" do
worker.perform("path")
expect(CacheBuster).to have_received(:bust_podcast).with("path")
end
end
end

0 comments on commit 3b3d2be

Please sign in to comment.