Rails + Sidekiq: Sidekiq running in wrong environment
ruby-on-rails
Solution
I think the solution you're looking for is namespace related.
https://github.com/mperham/sidekiq/wiki/Advanced-Options#wiki-using-sidekiqs-configure-blocks
This is what I use in my initializer.
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://localhost:6379/0',
namespace: "sidekiq_#{Rails.application.class.parent_name}_#{Rails.env}".downcase }
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://localhost:6379/0',
namespace: "sidekiq_#{Rails.application.class.parent_name}_#{Rails.env}".downcase }
end
Problem
I have a Rails 3 app that I deploy using Capistrano. I recently added Sidekiq. It works fine in my development. I'm hosting both `staging` and `preview` on the same server and it's preview that is not functioning properly. When I trigger the worker on preview it goes to staging and hits the staging database. Am I missing configuration to have 2 sidekiq processes coexist on the same server? Here's my deploy.rb: ``` require "bundler/capistrano" require 'sidekiq/capistrano' #<-- sidekiq load "lib/deployer/deployer.rb" set :application, "myapp" set :scm, :git set :repository, ... set :scm_passphrase, "" defaults global_defaults set :stages, ["staging", "preview"] task :staging do set :rails_env, "staging" set :user, "deployer" server "myserver.com", :app, :web, :db, :primary => true defaults end task :preview do set :rails_env, "preview" set :user, "deployer" server "myserver.com", :app, :web, :db, :primary => true defaults end ``` It's inconsistent. In preview I just did an action that triggers the worker, and 4 times it went to staging (I could see in the log as well as the console), and 1 time it hit preview like it was supposed to. Am I missing something?