简体   繁体   English

在Heroku上运行delayed_job工作者?

[英]Running delayed_job worker on Heroku?

So right now I have an implementation of delayed_job that works perfectly on my local development environment. 所以现在我有一个delayed_job的实现,它完全适用于我的本地开发环境。 In order to start the worker on my machine, I just run rake jobs:work and it works perfectly. 为了在我的机器上启动工作人员,我只是运行rake jobs:work ,它完美地工作。

To get delayed_job to work on heroku, I've been using pretty much the same command: heroku run rake jobs:work . 为了让delayed_job在heroku上工作,我一直在使用几乎相同的命令: heroku run rake jobs:work This solution works, without me having to pay anything for worker costs to Heroku, but I have to keep my command prompt window open or else the delayed_job worker stops when I close it. 这个解决方案可以工作,我不需要为Heroku支付任何工作成本,但是我必须保持命令提示窗口打开,否则我关闭时就会停止delayed_job工作。 Is there a command to permanently keep this delayed_job worker working even when I close the command window? 是否有命令永久保持这个delayed_job工作程序即使在我关闭命令窗口时也能正常工作? Or is there another better way to go about this? 或者还有另一种更好的方法吗?

I recommend the workless gem to run delayed jobs on heroku. 我推荐无用的宝石在heroku上运行延迟的工作。 I use this now - it works perfectly for me, zero hassle and at zero cost. 我现在使用它 - 它对我来说非常有效,零麻烦且零成本。

I have also used hirefireapp which gives a much finer degree of control on scaling workers. 我还使用了hirefireapp ,它可以对扩展工作者进行更精细的控制。 This costs, but costs less than a single heroku worker (over a month). 这需要花费,但成本低于单个heroku工作者(超过一个月)。 I don't use this now, but have used it, and it worked very well. 我现在不使用它,但已经使用过它,它运行得很好。

Add

worker: rake jobs:work

to your Procfile . 到您的Procfile

EDIT: 编辑:

Even if you run it from your console you 'buy' worker dyno but Heroku has per second biling. 即使你从你的控制台运行它你'买'工人dyno但是Heroku每秒钟都会被打包。 So you don't pay because you have 750h free, and month in worst case has 744h, so you have free 6h for your extra dynos, scheduler tasks and so on. 所以你不付钱,因为你有750小时的免费,而最坏的情况下有一个月有744小时,所以你有额外的dynos,调度任务等6小时免费。

I haven't tried it personally yet, but you might find nohup useful. 我还没有尝试过,但你可能会觉得nohup很有用。 It allows your process to run even though you have closed your terminal window. 即使您已关闭终端窗口,它也允许您的进程运行。 Link: http://linux.101hacks.com/unix/nohup-command/ 链接: http//linux.101hacks.com/unix/nohup-command/

Using heroku console to get workers onto the jobs will only create create a temporary dyno for the job. 使用heroku控制台让工作人员进入工作岗位只会为工作创建一个临时的dyno。 To keep the jobs running without cli, you need to put the command into the Procfile as @Lucaksz suggested. 要保持作业在没有cli的情况下运行,您需要将命令放入Procfile中,如@Lucaksz建议的那样。

After deployment, you also need to scale the dyno formation, as heroku need to know how many dyno should be put onto the process type like this: heroku ps:scale worker=1 部署之后,你还需要扩展dyno形式,因为heroku需要知道应该将多少dyno放到进程类型上,如下所示: heroku ps:scale worker = 1

More details can be read here https://devcenter.heroku.com/articles/scaling 更多细节可以在这里阅读https://devcenter.heroku.com/articles/scaling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM