didil / sidekiq-client-cli

Command line client for Sidekiq
MIT License
18 stars 18 forks source link

How to make sidekiq-client-cli working with environments? #15

Closed christophe-dufour closed 10 years ago

christophe-dufour commented 10 years ago

Hi there,

I use Sidekiq and Sidekiq in different environments (development/staging/production)

First at all, I try to configure my redis-server into my rails-app/config/environments/[development.rb | staging.rb | production.rb]

It took me a while to understand that sidekiq-client-cli does NOT read those files.

So I try to configure it into my rails-app/config/initilizers/sidekiq.rb

my code looks like this :

if Rails.env.production?
  Sidekiq.configure_server do |config|
    config.redis = {:url => 'redis://sidekiq.hidutyfree.com:7372/12'}
  end

  Sidekiq.configure_client do |config|
    config.redis = {:url => 'redis://sidekiq.hidutyfree.com:7372/12'}
  end
end

But in fact, when I call bundle exec sidekiq-client it raise an error and say

uninitialized constant Rails
config/initializers/sidekiq.rb:4:in `<top (required)>'

How to make it work?

didil commented 10 years ago

Hi Chistophe,

the error is due to the fact that sidekiq-client does not load rails as it is built to run without the need to load rails, so 'Rails' is not defined and therefore Rails.env.production? is not defined

A workaround could be to use ENV["RAILS_ENV"] == "production" instead

christophe-dufour commented 10 years ago

Hi didil,

Thank you for the answer.

It works for me :)

I this it can be a good idea to write it down somewhere into sidekiq-client-cli documentation.