【问题标题】:sidekiq does not generate sidekiq.pid file on heroku, using with Redistogosidekiq 不会在 Heroku 上生成 sidekiq.pid 文件,与 Redistogo 一起使用
【发布时间】:2014-11-18 07:58:57
【问题描述】:

两天来,我一直在努力让 sidekiq 在 heroku 生产环境上工作。我已经阅读了有关类似问题的所有可用文档,但仍然无法产生有效的解决方案,我真的需要一些帮助!

在 heroku 上部署后,我的应用程序崩溃并且我得到以下错误堆栈跟踪:

2014-09-23T23:38:40.905093+00:00 app[worker.1]: No such file or directory @ rb_sysopen - /app/tmp/pids/sidekiq.pid
2014-09-23T23:38:40.905122+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/bin/sidekiq:23:in `<main>'
2014-09-23T23:38:40.905119+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.2.5/bin/sidekiq:7:in `<top (required)>'
2014-09-23T23:38:40.905117+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.2.5/lib/sidekiq/cli.rb:347:in `write_pid'
2014-09-23T23:38:40.905115+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.2.5/lib/sidekiq/cli.rb:347:in `open'
2014-09-23T23:38:40.905121+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/bin/sidekiq:23:in `load'
2014-09-23T23:38:40.905118+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.2.5/lib/sidekiq/cli.rb:41:in `parse'
2014-09-23T23:38:40.905114+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.1.0/gems/sidekiq-3.2.5/lib/sidekiq/cli.rb:347:in `initialize'
2014-09-23T23:38:39.588001+00:00 heroku[worker.1]: State changed from starting to up

首先,sidekiq 在我的本地机器上工作正常。我正在将heroku的REDISTOGO用于redis,在本地生产中,sidekiq已正确指向REDISTOGO并且运行良好。

其次,根据堆栈跟踪,尤其是No such file or directory @ rb_sysopen - /app/tmp/pids/sidekiq.pid这一行;它使我认为由于某种原因sidekiq.pid 在heroku 上运行时未正确生成文件。在本地环境中,每次我在app/tmp/pids/ 目录中启动应用程序时都会生成sidekiq.pid 文件,并且每次都分配一个不同的pid 编号。我是 guessing,在 heroku 上运行时,sidekiq 尝试从该文件中读取但找不到它。

这是我Procfile中的内容:

web: bundle exec rails server
worker: bundle exec sidekiq -C config/sidekiq.yml

这是我config/sidekiq.yml中的内容

---
:verbose: true
:pidfile: ./tmp/pids/sidekiq.pid
:concurrency: 25
# Set timeout to 8 on Heroku, longer if you manage your own systems.
:timeout: 8
:queues:
  - carrierwave

这是我sidekiq.rb中的内容

Sidekiq.configure_server do |config|
  config.redis = { :url => ENV['REDISTOGO_URL'], :namespace => "mynamespece"}
end

Sidekiq.configure_client do |config|
    config.redis = { :url => ENV['REDISTOGO_URL'], :namespace => "mynamespece"}
end

更新1

我正在使用 carrierwavecarrierwave-backgroundersidekiq 同步。

【问题讨论】:

  • 你为什么要创建一个pidfile?
  • @MikePerham Hey Mike,我知道你是sidekiq的作者,感谢你对此事的关注!我不是故意使用pid。我是 sidekiq 的新手,我认为这是默认行为,因为在我的实施过程中,我没有遇到任何引用 pid 的配置。你会建议什么,我做错了什么吗?也许不使用 pid 是实现 sidekiq 的最佳方式?我没有找到太多关于 pid 部分的文档。
  • @MikePerham 在我的本地环境中,每次我使用foreman start 时,我都会看到以下行:17:28:57 web.1 | started with pid 20788 17:28:57 worker.1 | started with pid 20789 pid 号每次都会不同。
  • @MikePerham 对不起,我忘了在我原来的帖子中提到这一点;我正在使用carrierwavecarrierwave-backgroundersidekiq;所以也许使用pid 是通过实现carrierwave 做出的决定
  • 只需删除 Sidekiq.yml 中的 pidfile 行,应该可以修复它。

标签: ruby-on-rails heroku pid sidekiq redistogo


【解决方案1】:

此问题已通过以下操作解决:

1) 感谢@MikePerham 为我指明了正确的方向,首先我在sidekiq.yml 文件中删除了这一行:

:pidfile: ./tmp/pids/sidekiq.pid

2) 然后,在我的Procfile 中,我不得不使用以下行来替换原点:

web: bundle exec rails server -p $PORT
worker: bundle exec sidekiq -C config/sidekiq.yml

现在 sidekiq 可以正常使用 heroku 上的 redistogo 了。

【讨论】:

  • 这就像一个神奇的魅力。非常感谢!
【解决方案2】:

通过在项目根目录中的tmp 目录中创建pids 目录已修复

【讨论】:

    【解决方案3】:

    我发现将目录添加到存储库并重新部署应用程序很有用。

    mkdir -p tmp/pids
    touch tmp/pids/.gitkeep
    git add -f tmp/pids/.gitkeep
    git commit -m 'Keep tmp/pids directory in repo'
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 1970-01-01
      • 2012-08-28
      • 2023-04-11
      • 2014-07-14
      • 2019-02-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多