运行 rake 任务以在 Heroku 上启动 Resque 工作线程
因此,我在 Heroku 上设置了 Resque 和 redis,这就是我的 resque.rake
文件的样子:
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
我运行了 heroku rake jobs:work
并让一名工作人员运行。这非常有效。我的后台工作正在完成。
然后我对代码做了一些更改,推送到heroku,仍然看到有一个工作线程在运行。然而,当作业被添加到队列中时,工作人员没有收到任何作业。所以我再次运行 heroku rake jobs:work
,它说我有两个工作人员正在运行,并且我的工作正在完成。
我的问题是为什么会发生这种情况?我每次推送到heroku 时都需要运行这个rake 任务吗?有没有办法自动执行此操作?另外,虽然我有两个工人在运行,但似乎只有一个在工作。有没有办法回到一个工人那里?
So I have Resque and redis to go set up on Heroku and this is what my resque.rake
file looks like:
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
I ran heroku rake jobs:work
and got one worker running. This worked perfectly. My background jobs were being completed.
Then I made some changes in my code, pushed to heroku, and still saw that I had one worker running. However, while jobs were being added to the queue, the worker was not receiving any jobs. So I ran heroku rake jobs:work
again, it said I had two workers running, and my jobs were being completed.
My question is why did this happen? Do I need to run this rake task every time I push to heroku? Is there a way to automate this? Also, although I have two workers running, there seems to be only one that is working. Is there a way to get back to one worker?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 Procfile 在 heroku http://devcenter.heroku.com/articles/procfile
请记住,Procfile 用于新的 Heroku Cedar Stack。
You should use Procfile for resque jobs on heroku http://devcenter.heroku.com/articles/procfile
Keep in mind that Procfile is used on new Heroku Cedar Stack.
Resque 只需要一名工人。您需要运行
heroku rake jobs:work
或使用 Resque-Scheduler (cron,或运行该任务的东西)来自动运行您的作业。You only need one worker for Resque. You will need to run
heroku rake jobs:work
or use Resque-Scheduler (cron, or something to run that task) to to automatically run your jobs.