From d4a2f24c885ce9aa6d44fd75682f51fc4e7d8452 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Mon, 24 Aug 2020 08:23:11 -0500 Subject: [PATCH] [deploy] Refactor:Move Cache Busting Rake Tasks to Sidekiq (#9931) --- app/workers/bust_cache_path_worker.rb | 5 +++++ config/schedule.yml | 15 +++++++++++++++ lib/tasks/cache.rake | 9 --------- spec/workers/bust_cache_path_worker_spec.rb | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 app/workers/bust_cache_path_worker.rb delete mode 100644 lib/tasks/cache.rake create mode 100644 spec/workers/bust_cache_path_worker_spec.rb diff --git a/app/workers/bust_cache_path_worker.rb b/app/workers/bust_cache_path_worker.rb new file mode 100644 index 000000000..2e1b5270f --- /dev/null +++ b/app/workers/bust_cache_path_worker.rb @@ -0,0 +1,5 @@ +class BustCachePathWorker < BustCacheBaseWorker + def perform(path) + CacheBuster.bust(path) + end +end diff --git a/config/schedule.yml b/config/schedule.yml index 2c5628616..d8f622fbd 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -74,6 +74,21 @@ expire_old_listings: send_welcome_notifications: cron: "0 16 * * *" # daily at 4 pm UTC class: "Broadcasts::SendWelcomeNotificationsWorker" +hourly_feed_cache_bust: + cron: "0 * * * *" # hourly on the hour + class: "BustCachePathWorker" + args: + - "/feed.xml" +hourly_badge_cache_bust: + cron: "0 * * * *" # hourly on the hour + class: "BustCachePathWorker" + args: + - "/badge" +daily_home_cache_bust: + cron: "0 0 * * *" # daily at 12 am UTC + class: "BustCachePathWorker" + args: + - "/" send_email_digest: cron: "30 11 * * 3,4,5,6" # 11:30 am UTC Wed, Thurs, Fri, Sat, Sun class: "SendEmailDigestWorker" diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake deleted file mode 100644 index 5f358b135..000000000 --- a/lib/tasks/cache.rake +++ /dev/null @@ -1,9 +0,0 @@ -task periodic_cache_bust: :environment do - CacheBuster.bust("/feed.xml") - CacheBuster.bust("/badge") - CacheBuster.bust("/shecoded") -end - -task hourly_bust: :environment do - CacheBuster.bust("/") -end diff --git a/spec/workers/bust_cache_path_worker_spec.rb b/spec/workers/bust_cache_path_worker_spec.rb new file mode 100644 index 000000000..482bd16a8 --- /dev/null +++ b/spec/workers/bust_cache_path_worker_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +RSpec.describe BustCachePathWorker, type: :worker do + let(:worker) { subject } + + include_examples "#enqueues_on_correct_queue", "high_priority" + + describe "#perform" do + it "busts cache for given path" do + allow(CacheBuster).to receive(:bust) + worker.perform("/foo") + expect(CacheBuster).to have_received(:bust).with("/foo") + end + end +end