使用delayed_job的循环计划
是否可以使用delayed_job执行以下操作:
定义一个名为
Tasks
的类在Tasks run中有一个方法每 5 分钟后:
Tasks.do_processing
当下一个 5 分钟周期到来时周围,然后运行
Tasks.do_processing
仅如果前一个do_processing
已完成
这是我有的东西吗我自己创建还是可以delayed_job(或其他一些gem/插件)执行此操作?
Ps.我知道操作系统级别的 cron 作业,但如果我使用它,那就意味着每次 cron“触发”时,它都会重新加载整个 Rails 环境,而delayed_job只需要加载一次。
Is it possible to do the following using delayed_job:
Define a class called
Tasks
Have a method in Tasks run after every 5 minutes:
Tasks.do_processing
When the next 5 minute cycle comes around, then run
Tasks.do_processing
only if the previousdo_processing
has completed
Is this something I have to create on my own or can delayed_job (or some other gem/plugin) do this?
Ps. I know about OS-level cron jobs, but if I used that then it would mean that each time the cron "fired" it would re-load the entire Rails environment, whereas delayed_job only needs to load it once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以考虑创建一个 Rake 任务或其他类似的独立进程来处理此功能,然后用 守护进程:
You may consider creating a Rake task or other similar standalone processes that takes care of this functionality, and then wrapping it up with Daemons:
如果您想做类似的事情:
请尝试以下代码: https://gist.github.com /1024726
If you'd like to do something similar to this :
then try out this code: https://gist.github.com/1024726
我想我可能会补充一点, delayed_job_recurring gem 是 @kares 答案要点的扩展。
用法示例:
并安排它。在 Rails 应用程序中,您可以将其放入初始值设定项中:
Thought I might add that the delayed_job_recurring gem is an extension of the gist on @kares's answer.
Usage example:
And schedule it. In a rails app, you might put this in an initializer:
在 DJ 2.1 的生产中使用 this 版本已经有一段时间了。没有黑客行为,使用内置的延迟作业挂钩。只需确保将名为“queue”的列添加到延迟作业表中,我相信 DJ 3 无论如何都会将其添加到表中。
Been using a version of this in production for a while now for DJ 2.1 . No hackery, uses Delayed Jobs built in hooks. Just make sure you add column named 'queue' to the delayed jobs table, which I believe is something DJ 3 added to the table anyways.
您可以使用 https://github.com/codez/delayed_cron_job 这是一个延迟作业插件来设置周期工作机会。
You can use https://github.com/codez/delayed_cron_job which is a Delayed Job plugin to set periodical jobs.
定期延迟作业:
http://rifkifauzi.wordpress.com/2010/07/29/8 /
Recurring delayed_job:
http://rifkifauzi.wordpress.com/2010/07/29/8/