Change Sidekiq readiness file to use an environment variable (#30988)

main
Renaud Chaput 2024-07-10 14:57:25 +02:00 committed by GitHub
parent 182b9248c0
commit 36592d10aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View File

@ -67,7 +67,9 @@ ENV \
# Optimize jemalloc 5.x performance # Optimize jemalloc 5.x performance
MALLOC_CONF="narenas:2,background_thread:true,thp:never,dirty_decay_ms:1000,muzzy_decay_ms:0" \ MALLOC_CONF="narenas:2,background_thread:true,thp:never,dirty_decay_ms:1000,muzzy_decay_ms:0" \
# Enable libvips, should not be changed # Enable libvips, should not be changed
MASTODON_USE_LIBVIPS=true MASTODON_USE_LIBVIPS=true \
# Sidekiq will touch tmp/sidekiq_process_has_started_and_will_begin_processing_jobs to indicate it is ready. This can be used for a readiness check in Kubernetes
MASTODON_SIDEKIQ_READY_FILENAME=sidekiq_process_has_started_and_will_begin_processing_jobs
# Set default shell used for running commands # Set default shell used for running commands
SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-c"] SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-c"]

View File

@ -2,19 +2,24 @@
require_relative '../../lib/mastodon/sidekiq_middleware' 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| Sidekiq.configure_server do |config|
config.redis = REDIS_SIDEKIQ_PARAMS 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 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 # This comes from https://github.com/sidekiq/sidekiq/wiki/Kubernetes#sidekiq
config.on(:startup) do ready_filename = ENV.fetch('MASTODON_SIDEKIQ_READY_FILENAME', nil)
FileUtils.touch(SIDEKIQ_WILL_PROCESSES_JOBS_FILE) if ready_filename
end raise 'MASTODON_SIDEKIQ_READY_FILENAME is not a valid filename' if File.basename(ready_filename) != ready_filename
config.on(:shutdown) do ready_path = Rails.root.join('tmp', ready_filename)
FileUtils.rm_f(SIDEKIQ_WILL_PROCESSES_JOBS_FILE)
config.on(:startup) do
FileUtils.touch(ready_path)
end
config.on(:shutdown) do
FileUtils.rm_f(ready_path)
end
end end
config.server_middleware do |chain| config.server_middleware do |chain|