Cron 和delayed_job - 在 Heroku 中同时使用两者

发布于 2024-12-10 12:48:53 字数 348 浏览 0 评论 0原文

我是否正确地认为,在heroku上每2小时运行一次后台进程(例如发送电子邮件/统计信息收集等)的最有效方法是使用一个cron,每两个小时安排一次,然后将项目粘贴到delayed_jobs队列中(基于 dj gem),然后立即被 Heroku 工作人员拾取?

除此之外,一旦应用程序投入生产,我认为具有成本效益的方法是让 Hirefire 启动一名工人来执行这项工作,然后再将其关闭,这种想法是否正确?

我还应该考虑其他方法吗?我以前没有做过这种延迟的工作 - 在开发和上线之前的基本生产测试中,我都基于 Heroku cron - 但在生产中,如果 cron 作业的负载增加,这似乎不明智。

任何有关有价值的替代方法的指示都表示赞赏!

Am I right in thinking the most efficient way to run a background process every 2 hours on heroku (e.g. sending emails / stats collection etc.) is to use a cron, scheduled for every two hours, that then sticks items in a delayed_jobs queue (based on the dj gem) that is then picked up by a heroku worker instantly?

Further to that, once the app is in production, am I right in thinking the cost-effective approach would be to have hirefire spin up a worker to carry out the job and then shut it down afterwards?

Are there other approaches I should consider? I have not done this kind of delayed job work before - in development and in basic production testing before go live I have it all based on a heroku cron - but in production that doesn't seem sensible if the load on the cron job increases.

Any pointers on worthwhile alternative approaches appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-12-17 12:48:53

如果您没有全职工作需要员工做,那么 Hirefire 绝对是您的最佳选择,否则您将支付休眠员工的费用。

计时的另一个选项是使用可用的 :run_at 参数让延迟的作业在完成时重新安排自己。然后,工作人员会在到达时间时执行此操作(尽管我从未测试过这是否可以与 Hirefire 一起使用,因为我认为他们只是查看作业数量)

总体而言,这是一种非常合理的方法,也是我将使用的方法。

Hirefire is definitely the way to go if you don't have a full time set of work for a worker to do as you'll be paying for a dormant worker otherwise.

Another option for the timing is to get the delayed job to reschedule itself when it completes using the :run_at argument that's available. The worker will then do it when it's hit the time (although I've never tested this would work with Hirefire as I think they just look at Job count)

It's a pretty sound approach overall, and what I would use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文