使用 Ruby 在 Rails 上 运行 在 Heroku 上完成一项长期任务的最佳方法是什么?

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

我正在寻找在 Heroku 中 运行 一项非常长的任务的最佳方法。

我使用 Ruby On Rails 作为我的 Web 应用程序,我有一个很长的任务,我想在每周日的晚上 运行 完成它。大约需要 15~20 分钟。我已经有了 Rufus-Scheduler,但我不确定这是最有效的解决方案。

我还找到了一些关于 Backgrounding Tasks in Heroku with Delayed Job 的东西。但这是处理它的最佳方式吗?

谢谢。

这就是我每天晚上 运行 的工作:https://devcenter.heroku.com/articles/scheduler

如果您的作业配置为 rake 任务,它会非常有效。 link 上的指南向您展示了如何配置所有内容,甚至解决了 运行 长时间的作业。

Heroku 不推荐使用 Heroku Scheduler 运行 长时间 运行ning 作业。

Heroku says,

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.

因此,在我看来,最好的方法是使用 Heroku Scheduler 运行 为每一种工作(短期或长期)分配任务,但如果任务花费的时间超过几分钟,那么我会简单地在该 rake 任务中创建一个后台作业。这样,调度程序永远不会 运行 超过几分钟。