Search code examples
ruby-on-railsruby-on-rails-3sidekiq

Using multiple sidekiq databases


Hey I am attempting to spawn a sidekiq worker that connects to a completely separate Redis database. I know with 3.0's connection pooling this is possible, and I have been able to successfully push a job onto the correct Redis DB, but the problem is the Sidekiq web UI is not showing these jobs in the queue (I have mounted a separate Rack app for this that points exclusively to the other Redis DB). The "Busy" tab in the admin interface also shows my sidekiq workers that I have pointed at this DB, with correct PIDs.

Here's my sidekiq.rb:

Sidekiq.configure_server do |config|
  if ENV['REDIS_DB'] == "2"
    config.redis = { :url => "redis://#{SIDEKIQ_HOST}:6379/2", :namespace => 'drip' }
  else
    config.redis = { :url => "redis://#{SIDEKIQ_HOST}:6379", :namespace => 'drip' }
  end
end

Sidekiq.configure_client do |config|
  if ENV['REDIS_DB'] == "2"
    config.redis = { :url => "redis://#{SIDEKIQ_HOST}:6379/2", :namespace => 'drip' }
  else
    config.redis = { :url => "redis://#{SIDEKIQ_HOST}:6379", :namespace => 'drip' }
  end
end

My use case is that I need to have fine grain control over the jobs that go into the second database, so I need the workers configured precisely so they are only using as many resources as I need them to. I only want the workers that are configured in this way to pick up these jobs.


Solution

  • The Web UI cannot be mounted multiple times to point to multiple Redises in a single process. You have to run multiple web processes with REDIS_DB set too.