【发布时间】:2017-01-25 00:50:13
【问题描述】:
我有一个免费的 heroku 帐户,我在其中部署了我的 rails 应用程序。我还启用了 redis heroku 插件。我的应用程序会抓取网站,在我的本地环境中需要 93 分钟才能完成。所以我决定把它放在后台任务中并在那里运行。我按照一些教程让后台任务在免费的 Heroku 帐户中运行,所以我使用了独角兽服务器。在本地测试它时,我的应用程序运行良好,但是一旦我将它部署到 heroku 并浏览我的项目站点,它就不起作用了。这是来自heroku log
2016-09-16T17:40:40.934711+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:40.943447+00:00 app[web.1]: E, [2016-09-16T17:40:40.943337 #3] ERROR -- : reaped #<Process::Status: pid 13987 exit 1> worker=2
2016-09-16T17:40:40.951820+00:00 app[web.1]: E, [2016-09-16T17:40:40.946468 #13992] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:40.951822+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:40.951824+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:40.951824+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:40.951825+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:40.951826+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:40.951826+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:40.951827+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:40.951828+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:40.951829+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:40.961433+00:00 app[web.1]: E, [2016-09-16T17:40:40.961347 #3] ERROR -- : reaped #<Process::Status: pid 13992 exit 1> worker=1
2016-09-16T17:40:40.966761+00:00 app[web.1]: E, [2016-09-16T17:40:40.953957 #13996] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:40.966764+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:40.966765+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:40.966766+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:40.966767+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:40.966767+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:40.966768+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:40.966769+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:40.966770+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:40.966771+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:40.968861+00:00 app[web.1]: E, [2016-09-16T17:40:40.944646 #13990] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:40.968863+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:40.968864+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:40.968865+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:40.968866+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:40.968867+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:40.968872+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:40.968871+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:40.968873+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:40.977007+00:00 app[web.1]: E, [2016-09-16T17:40:40.976925 #3] ERROR -- : reaped #<Process::Status: pid 13990 exit 1> worker=0
2016-09-16T17:40:40.968873+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:40.977910+00:00 app[web.1]: E, [2016-09-16T17:40:40.965528 #13999] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:40.977913+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:40.977914+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:40.977914+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:40.977915+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:40.977916+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:40.977917+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:40.977918+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:40.977918+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:40.977919+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:40.981913+00:00 app[web.1]: E, [2016-09-16T17:40:40.981796 #3] ERROR -- : reaped #<Process::Status: pid 13996 exit 1> worker=2
2016-09-16T17:40:40.982020+00:00 app[web.1]: E, [2016-09-16T17:40:40.981968 #3] ERROR -- : reaped #<Process::Status: pid 13999 exit 1> worker=1
2016-09-16T17:40:40.998699+00:00 app[web.1]: E, [2016-09-16T17:40:40.985434 #14004] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:40.998703+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:40.998704+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:40.998705+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:40.998706+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:40.998707+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:40.998708+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:40.998708+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:40.998709+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:40.998710+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:41.013015+00:00 app[web.1]: E, [2016-09-16T17:40:41.012891 #3] ERROR -- : reaped #<Process::Status: pid 14004 exit 1> worker=0
2016-09-16T17:40:41.013269+00:00 app[web.1]: E, [2016-09-16T17:40:40.992746 #14009] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:41.013271+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:41.013272+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:41.013272+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:41.013273+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:41.013274+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:41.013275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:41.013276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:41.013276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:41.013277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:41.015082+00:00 app[web.1]: E, [2016-09-16T17:40:40.991259 #14006] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:41.015083+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:41.015084+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:41.015085+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:41.015086+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:41.015087+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:41.015088+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:41.015086+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:41.015088+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:41.015089+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:41.029456+00:00 app[web.1]: E, [2016-09-16T17:40:41.019600 #14013] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:41.029459+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:41.029461+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:41.029462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:41.029461+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:41.029462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:41.029464+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:41.029464+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:41.029465+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:41.029466+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:41.033517+00:00 app[web.1]: E, [2016-09-16T17:40:41.032905 #3] ERROR -- : reaped #<Process::Status: pid 14006 exit 1> worker=1
2016-09-16T17:40:41.033606+00:00 app[web.1]: E, [2016-09-16T17:40:41.033566 #3] ERROR -- : reaped #<Process::Status: pid 14009 exit 1> worker=2
2016-09-16T17:40:41.034410+00:00 app[web.1]: E, [2016-09-16T17:40:41.034370 #3] ERROR -- : reaped #<Process::Status: pid 14013 exit 1> worker=0
2016-09-16T17:40:41.067342+00:00 app[web.1]: E, [2016-09-16T17:40:41.057962 #14018] ERROR -- : uninitialized constant #<Class:#<Unicorn::Configurator:0x007f7b03390af0>>::Sidekiq (NameError)
2016-09-16T17:40:41.067346+00:00 app[web.1]: ./config/unicorn.rb:7:in `block in reload'
2016-09-16T17:40:41.067347+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:611:in `init_worker_process'
2016-09-16T17:40:41.067347+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:639:in `worker_loop'
2016-09-16T17:40:41.067348+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
2016-09-16T17:40:41.067349+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:519:in `maintain_worker_count'
2016-09-16T17:40:41.067349+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:283:in `join'
2016-09-16T17:40:41.067350+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
2016-09-16T17:40:41.067351+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
2016-09-16T17:40:41.067352+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
2016-09-16T17:40:41.077263+00:00 app[web.1]: E, [2016-09-16T17:40:41.077156 #3] ERROR -- : reaped #<Process::Status: pid 14018 exit 1> worker=1
这是我的独角兽配置
独角兽.rb
before_fork do |server, worker|
@sidekiq_pid ||= spawn("bundle exec sidekiq -c 2")
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
end
Procfile
web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
【问题讨论】:
-
我会考虑使用 Heroku 的任务调度程序并将后台抓取工具设置为在 rake 任务中运行(比使用 sidekiq 简单得多)。然后只需使用正确的 Procfile 就可以了。此外,您不需要在 Heroku 上使用 RedisToGo,因为他们的调度程序将通过 rake 执行它。如果您想完整地写下如何走这条路,请告诉我,我会发布答案。
-
嗨@bkunzi01,在阅读了 Heroku
s task scheduler I found outAnything 上的文档后,任何需要超过几分钟才能完成的事情都应该使用工作测功机来运行。`关于这个。我的爬虫需要 93 分钟才能完全运行,所以任务调度程序会帮我解决这个问题吗? -
@bkunzi01 ,你好,如果你不介意,你能把完整的文章贴出来吗?
-
没有问题。接听来电
标签: ruby-on-rails heroku sidekiq unicorn