2017-05-03 23:18:13 +02:00
|
|
|
# frozen_string_literal: true
|
2016-03-25 02:50:48 +01:00
|
|
|
|
2022-04-28 17:47:34 +02:00
|
|
|
require_relative '../../lib/mastodon/sidekiq_middleware'
|
2021-12-27 00:47:20 +01:00
|
|
|
|
2016-03-25 02:50:48 +01:00
|
|
|
Sidekiq.configure_server do |config|
|
2024-09-02 16:19:55 +02:00
|
|
|
config.redis = REDIS_CONFIGURATION.sidekiq
|
2018-02-25 03:16:11 +09:00
|
|
|
|
2024-07-09 12:47:08 +02:00
|
|
|
# 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
|
2024-07-10 14:57:25 +02:00
|
|
|
ready_filename = ENV.fetch('MASTODON_SIDEKIQ_READY_FILENAME', nil)
|
|
|
|
if ready_filename
|
|
|
|
raise 'MASTODON_SIDEKIQ_READY_FILENAME is not a valid filename' if File.basename(ready_filename) != ready_filename
|
|
|
|
|
|
|
|
ready_path = Rails.root.join('tmp', ready_filename)
|
|
|
|
|
|
|
|
config.on(:startup) do
|
|
|
|
FileUtils.touch(ready_path)
|
|
|
|
end
|
2024-07-09 12:47:08 +02:00
|
|
|
|
2024-07-10 14:57:25 +02:00
|
|
|
config.on(:shutdown) do
|
|
|
|
FileUtils.rm_f(ready_path)
|
|
|
|
end
|
2024-07-09 12:47:08 +02:00
|
|
|
end
|
|
|
|
|
2025-01-27 13:52:30 +01:00
|
|
|
if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
|
|
|
|
require 'prometheus_exporter'
|
|
|
|
require 'prometheus_exporter/instrumentation'
|
|
|
|
|
|
|
|
config.on :startup do
|
|
|
|
# Ruby process metrics (memory, GC, etc)
|
|
|
|
PrometheusExporter::Instrumentation::Process.start type: 'sidekiq'
|
|
|
|
|
|
|
|
# Sidekiq process metrics (concurrency, busy, etc)
|
|
|
|
PrometheusExporter::Instrumentation::SidekiqProcess.start
|
|
|
|
|
|
|
|
# ActiveRecord metrics (connection pool usage)
|
|
|
|
PrometheusExporter::Instrumentation::ActiveRecord.start(
|
|
|
|
custom_labels: { type: 'sidekiq' },
|
|
|
|
config_labels: [:database, :host]
|
|
|
|
)
|
|
|
|
|
|
|
|
if ENV['MASTODON_PROMETHEUS_EXPORTER_SIDEKIQ_DETAILED_METRICS'] == 'true'
|
|
|
|
# Optional, as those metrics might generate extra overhead and be redundant with what OTEL provides
|
|
|
|
|
|
|
|
# Per-job metrics
|
|
|
|
config.server_middleware do |chain|
|
|
|
|
chain.add PrometheusExporter::Instrumentation::Sidekiq
|
|
|
|
end
|
|
|
|
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
|
|
|
|
|
|
|
|
# Per-queue metrics for queues handled by this process (size, latency, etc)
|
|
|
|
# They will be reported by every process handling those queues, so do not sum them up
|
|
|
|
PrometheusExporter::Instrumentation::SidekiqQueue.start
|
|
|
|
|
|
|
|
# Global Sidekiq metrics (size of the global queues, number of jobs, etc)
|
|
|
|
# Will be the same for every Sidekiq process
|
|
|
|
PrometheusExporter::Instrumentation::SidekiqStats.start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
at_exit do
|
|
|
|
# Wait for the latest metrics to be reported before shutting down
|
|
|
|
PrometheusExporter::Client.default.stop(wait_timeout_seconds: 10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-25 03:16:11 +09:00
|
|
|
config.server_middleware do |chain|
|
2022-04-28 17:47:34 +02:00
|
|
|
chain.add Mastodon::SidekiqMiddleware
|
2018-02-25 03:16:11 +09:00
|
|
|
end
|
2020-03-31 21:59:03 +02:00
|
|
|
|
2021-03-15 11:17:43 +01:00
|
|
|
config.server_middleware do |chain|
|
|
|
|
chain.add SidekiqUniqueJobs::Middleware::Server
|
|
|
|
end
|
|
|
|
|
|
|
|
config.client_middleware do |chain|
|
|
|
|
chain.add SidekiqUniqueJobs::Middleware::Client
|
2020-03-31 21:59:03 +02:00
|
|
|
end
|
2021-03-15 11:17:43 +01:00
|
|
|
|
2023-10-23 17:46:21 +02:00
|
|
|
config.on(:startup) do
|
|
|
|
if SelfDestructHelper.self_destruct?
|
|
|
|
Sidekiq.schedule = {
|
|
|
|
'self_destruct_scheduler' => {
|
|
|
|
'interval' => ['1m'],
|
|
|
|
'class' => 'Scheduler::SelfDestructScheduler',
|
|
|
|
'queue' => 'scheduler',
|
|
|
|
},
|
|
|
|
}
|
2024-02-06 16:32:09 +01:00
|
|
|
SidekiqScheduler::Scheduler.instance.reload_schedule!
|
2023-10-23 17:46:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-15 11:17:43 +01:00
|
|
|
SidekiqUniqueJobs::Server.configure(config)
|
2016-03-25 02:50:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
Sidekiq.configure_client do |config|
|
2024-09-02 16:19:55 +02:00
|
|
|
config.redis = REDIS_CONFIGURATION.sidekiq
|
2021-03-15 11:17:43 +01:00
|
|
|
|
|
|
|
config.client_middleware do |chain|
|
|
|
|
chain.add SidekiqUniqueJobs::Middleware::Client
|
|
|
|
end
|
2016-03-25 02:50:48 +01:00
|
|
|
end
|
2018-04-10 16:08:28 +02:00
|
|
|
|
2020-03-21 12:04:54 +09:00
|
|
|
Sidekiq.logger.level = ::Logger.const_get(ENV.fetch('RAILS_LOG_LEVEL', 'info').upcase.to_s)
|
2021-03-15 11:17:43 +01:00
|
|
|
|
|
|
|
SidekiqUniqueJobs.configure do |config|
|
2023-11-09 11:19:04 -05:00
|
|
|
config.enabled = !Rails.env.test?
|
2021-03-15 11:17:43 +01:00
|
|
|
config.reaper = :ruby
|
|
|
|
config.reaper_count = 1000
|
|
|
|
config.reaper_interval = 600
|
|
|
|
config.reaper_timeout = 150
|
2022-10-26 12:10:48 +02:00
|
|
|
config.lock_ttl = 50.days.to_i
|
2021-03-15 11:17:43 +01:00
|
|
|
end
|