【问题标题】:Troubleshooting Sidekiq workers on Heroku Production site对 Heroku 生产站点上的 Sidekiq 工作人员进行故障排除
【发布时间】:2022-01-21 00:04:39
【问题描述】:

我一直在我的开发环境中本地测试我的 sidekiq 工作人员,他们工作正常。但是,当我推送到 Heroku 时,我似乎无法让我的工人开始。

我不确定解决此问题的最佳方法,但这里有一些信息:

Procfile:

web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb

我没有 sidekiq.yaml 文件。

独角兽.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

调用我的工作人员的 Rake 任务:

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 的生产环境中发生但在本地运行良好?

【问题讨论】:

    标签: ruby-on-rails heroku sidekiq worker


    【解决方案1】:

    在您的 procfile 中,您需要启动 sidekiq 进程:

    # Procfile
    web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
    worker: bundle exec sidekiq
    

    确实,这就是我们在开发机器上启动sidekiq、打开终端窗口并运行sidekiq 命令的操作。你的 unicorn.rb 只配置 Sidekiq,不会启动它。

    注意:部署后,您必须在 heroku 上启动一个 worker:

    heroku ps:scale workers=1
    

    【讨论】:

    • 太棒了 - 感谢您的提示!
    • heroku ps:scale workers=1 注意s 中的workers
    • 已修复。谢谢@ShoaibBurq
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多