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')
username = ENV.fetch('REDIS_SIDEKIQ_USERNAME')
password = ENV.fetch('REDIS_SIDEKIQ_PASSWORD')
@ -7,14 +11,19 @@ if ENV.has_key?('REDIS_SIDEKIQ_SENTINELS')
.map { URI.parse(_1) }
.map { { host: _1.host, port: _1.port, username:, password: } }
Sidekiq.configure_server do |config|
config.redis = {
{
name:,
sentinels:,
username:,
password:,
role: :master
}
else
{} # default config from REDIS_URL
end
Sidekiq.configure_server do |config|
config.redis = sidekiq_redis
if ENV['PROMETHEUS_EXPORTER_ENABLED'] == 'enabled'
Yabeda.configure!
@ -24,20 +33,8 @@ if ENV.has_key?('REDIS_SIDEKIQ_SENTINELS')
if ENV['SKIP_RELIABLE_FETCH'].blank?
Sidekiq::ReliableFetch.setup_reliable_fetch!(config)
end
config.capsule('api_entreprise') do |cap|
cap.concurrency = 1
cap.queues = ['api_entreprise']
end
end
Sidekiq.configure_client do |config|
config.redis = {
name:,
sentinels:,
username:,
password:,
role: :master
}
end
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
ActiveSupport.on_load(:after_initialize) do
class ActiveStorage::PurgeJob < ActiveStorage::BaseJob