chore(sidekiq): support for standard/local config without redis sentinels

This commit is contained in:
Colin Darie 2024-04-10 11:37:20 +02:00
parent 137601448b
commit e1144cf655
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
2 changed files with 26 additions and 31 deletions

View file

@ -1,4 +1,8 @@
if ENV.has_key?('REDIS_SIDEKIQ_SENTINELS') SIDEKIQ_ENABLED = ENV.key?('REDIS_SIDEKIQ_SENTINELS') || ENV.key?('REDIS_URL') || ENV['RAILS_QUEUE_ADAPTER'] == 'sidekiq'
return if !SIDEKIQ_ENABLED
sidekiq_redis = if ENV.key?('REDIS_SIDEKIQ_SENTINELS')
name = ENV.fetch('REDIS_SIDEKIQ_MASTER') name = ENV.fetch('REDIS_SIDEKIQ_MASTER')
username = ENV.fetch('REDIS_SIDEKIQ_USERNAME') username = ENV.fetch('REDIS_SIDEKIQ_USERNAME')
password = ENV.fetch('REDIS_SIDEKIQ_PASSWORD') password = ENV.fetch('REDIS_SIDEKIQ_PASSWORD')
@ -7,37 +11,30 @@ if ENV.has_key?('REDIS_SIDEKIQ_SENTINELS')
.map { URI.parse(_1) } .map { URI.parse(_1) }
.map { { host: _1.host, port: _1.port, username:, password: } } .map { { host: _1.host, port: _1.port, username:, password: } }
Sidekiq.configure_server do |config| {
config.redis = { name:,
name:, sentinels:,
sentinels:, username:,
username:, password:,
password:, role: :master
role: :master }
} else
{} # default config from REDIS_URL
end
if ENV['PROMETHEUS_EXPORTER_ENABLED'] == 'enabled' Sidekiq.configure_server do |config|
Yabeda.configure! config.redis = sidekiq_redis
Yabeda::Prometheus::Exporter.start_metrics_server!
end
if ENV['SKIP_RELIABLE_FETCH'].blank? if ENV['PROMETHEUS_EXPORTER_ENABLED'] == 'enabled'
Sidekiq::ReliableFetch.setup_reliable_fetch!(config) Yabeda.configure!
end Yabeda::Prometheus::Exporter.start_metrics_server!
config.capsule('api_entreprise') do |cap|
cap.concurrency = 1
cap.queues = ['api_entreprise']
end
end end
Sidekiq.configure_client do |config| if ENV['SKIP_RELIABLE_FETCH'].blank?
config.redis = { Sidekiq::ReliableFetch.setup_reliable_fetch!(config)
name:,
sentinels:,
username:,
password:,
role: :master
}
end end
end end
Sidekiq.configure_client do |config|
config.redis = sidekiq_redis
end

View file

@ -1,5 +1,3 @@
SIDEKIQ_ENABLED = ENV.has_key?('REDIS_SIDEKIQ_SENTINELS') || ENV.has_key?('REDIS_URL')
if Rails.env.production? && SIDEKIQ_ENABLED if Rails.env.production? && SIDEKIQ_ENABLED
ActiveSupport.on_load(:after_initialize) do ActiveSupport.on_load(:after_initialize) do
class ActiveStorage::PurgeJob < ActiveStorage::BaseJob class ActiveStorage::PurgeJob < ActiveStorage::BaseJob