From 7542a134d5fecf82d14dcc1860be87cf6645ec7f Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Tue, 9 Jul 2024 12:47:08 +0200 Subject: [PATCH] Add a file for Sidekiq to signal it is ready to process jobs (#30971) --- config/initializers/sidekiq.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 53b02edc402..e1d98b8ba3b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -2,9 +2,21 @@ require_relative '../../lib/mastodon/sidekiq_middleware' +SIDEKIQ_WILL_PROCESSES_JOBS_FILE = Rails.root.join('tmp', 'sidekiq_process_has_started_and_will_begin_processing_jobs').freeze + Sidekiq.configure_server do |config| config.redis = REDIS_SIDEKIQ_PARAMS + # This is used in Kubernetes setups, to signal that the Sidekiq process has started and will begin processing jobs + # This comes from https://github.com/sidekiq/sidekiq/wiki/Kubernetes#sidekiq + config.on(:startup) do + FileUtils.touch(SIDEKIQ_WILL_PROCESSES_JOBS_FILE) + end + + config.on(:shutdown) do + FileUtils.rm_f(SIDEKIQ_WILL_PROCESSES_JOBS_FILE) + end + config.server_middleware do |chain| chain.add Mastodon::SidekiqMiddleware end