为什么Sidekiq在服务器的开发环境中运行?

时间:2018-08-30 18:32:20

标签: ruby-on-rails environment-variables sidekiq

在我的nginx网站配置文件(/etc/nginx/sites-available/my_website中已设置:

passenger_env_var RAILS_ENV staging;

我正在使用Sidekiq发送电子邮件,如下所示:

bundle exec sidekiq -q mailers -d -L log/sidekiq.log

但是我的Sidekiq的环境设置为development。为什么?

启动sidekiq时是否必须显式设置环境?我认为它是由nginx配置设置的。

谢谢

2 个答案:

答案 0 :(得分:2)

Sidekiq的默认环境为development。设置它的一种方法是像这样运行sidekiq

bundle exec sidekiq --environment production

答案 1 :(得分:1)

可以通过在initializers/sidekiq.rb下创建文件来配置它

If Rails.env.development?
  Sidekiq.configure_server do |config|
    config.redis = { url: 'redis://localhost:6379/0', namespace: "name_{Rails.env}" }
  end

  Sidekiq.configure_client do |config|
    config.redis = { url: 'redis://localhost:6379/0', namespace: "name_{Rails.env}" }
  end
elsif Rails.env.staging?
  Sidekiq.configure_server do |config|
    config.redis = { url: 'redis://redis-xx.xxxx.xxxx.xx.xxx.amazonaws.com:6379/12', namespace: "name_#{Rails.env}" }
  end

  Sidekiq.configure_client do |config|
    config.redis = { url: 'redis://redis-xx.xxxx.xxxx.xx.xxx.amazonaws.com:6379/12', namespace: "name_#{Rails.env}" }
  end
end