我一直在我的开发环境中测试我的sidekiq工作者,他们工作正常.然而,当我推到Heroku时,我似乎无法让我的工人开始.
我不确定解决此问题的最佳方法,但这里有一些信息:
Procfile:web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
我没有sidekiq.yaml文件.
Unicorn.rb:worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 9999 preload_app true before_fork do |server, worker| @sidekiq_pid ||= spawn("bundle exec sidekiq -c 2") Signal.trap 'TERM' do puts 'Unicorn master intercepting TERM and sending myself QUIT instead' Process.kill 'QUIT', Process.pid end defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end worker_processes 3 after_fork do |server, worker| Sidekiq.configure_client do |config| config.redis = { :size => 1 } end Sidekiq.configure_server do |config| config.redis = { :size => 5 } end Signal.trap 'TERM' do puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' end defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
调用我的工人的佣金任务:
namespace :ivr do desc "For IVR" task get_welcome: :environment do NmeContactListWorker.perform_async('Welcome', 'IVR') end end
当我调用这个rake任务时,我在heroku日志中得到以下内容:
2014-03-19T13:11:32.716759+00:00 heroku[api]: Starting process with command `bundle exec rake ivr:get_welcome` by test@gmail.com 2014-03-19T13:11:38.795843+00:00 heroku[run.3843]: State changed from starting to up 2014-03-19T13:11:38.711077+00:00 heroku[run.3843]: Awaiting client 2014-03-19T13:11:38.794029+00:00 heroku[run.3843]: Starting process with command `bundle exec rake ivr:get_welcome` 2014-03-19T13:11:47.171071+00:00 heroku[run.3843]: Process exited with status 0 2014-03-19T13:11:47.209653+00:00 heroku[run.3843]: State changed from up to complete
我不确定如何更好地了解我的工人失败的原因.什么可能导致这在Heroku的生产中发生,但在本地工作正常?
在proc文件中,您需要启动sidekiq进程:
# Procfile web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb worker: bundle exec sidekiq
实际上,这就是我们在dev机器上启动sidekiq,打开终端窗口并运行sidekiq
命令.你的unicorn.rb只配置Sidekiq,而不是启动它.
注意:一旦部署,你必须在heroku上启动一个worker:
heroku ps:scale worker=1