简体   繁体   English

使用Ruby On Rails在Heroku上运行长任务的最佳方法是什么?

[英]What is the best way to run a long task on Heroku with Ruby On Rails?

I am looking for the best way to run a very long task in Heroku. 我正在寻找在Heroku中执行一项非常长的任务的最佳方法。

I use Ruby On Rails for my web application and I have a very long task that I want to run it every week on Sunday during the night. 我使用Ruby On Rails作为我的Web应用程序,我有一个很长的任务,我希望每周星期天在晚上运行它。 It takes around 15~20 minutes. 大约需要15~20分钟。 I already have Rufus-Scheduler , but I am not sure it is the most effective solution. 我已经有了Rufus-Scheduler ,但我不确定它是最有效的解决方案。

I also find something about Backgrounding Tasks in Heroku with Delayed Job . 我还发现了Heroku中具有延迟作业的 后台任务 But is it the best way to handle it ? 但这是处理它的最佳方式吗?

Thanks. 谢谢。

This is what I use for a job that I run every night: https://devcenter.heroku.com/articles/scheduler 这就是我每晚运行的工作: https//devcenter.heroku.com/articles/scheduler

It works really well if your job is configured as a rake task. 如果您的工作配置为rake任务,它的效果非常好。 The guide at the link shows you how to configure everything and even addresses long-running jobs. 链接指南向您展示如何配置所有内容,甚至可以解决长时间运行的作业。

Heroku does not recommend to run long-running jobs with Heroku Scheduler. Heroku不建议使用Heroku Scheduler运行长时间运行的作业。

Heroku says, Heroku说,

Scheduled jobs are meant to execute short running tasks or enqueue longer running tasks into a background job queue. 计划作业用于执行短期运行任务或将较长时间运行的任务排入后台作业队列。 Anything that takes longer than a couple of minutes to complete should use a worker dyno to run. 任何需要花费超过几分钟才能完成的事情应该使用工作人员dyno来运行。

So, in my opinion, the best approach would be to use Heroku Scheduler to run rake task for every kind of job (short or long) but if a task takes longer than a couple of minutes then I would simply create a Background Job within that rake task. 因此,在我看来,最好的方法是使用Heroku Scheduler为每种工作(短期或长期)运行rake任务,但如果任务需要的时间超过几分钟,那么我只需在其中创建一个后台作业耙任务。 That way the scheduler will never run longer than a couple of minutes. 这样,调度程序永远不会运行超过几分钟。

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

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