Rails 的“delayed_job”是吗?真的是为了 cron 任务吗?
Delayed_job位于http://github.com/collectiveidea/delayed_job
delayed_job是否有能力执行cron任务?比如每晚凌晨 1 点运行一个脚本。或者每 1 小时运行一个脚本。
如果不能的话,有哪些合适的宝石可以做到这一点?是否可以使用浏览器进行远程监控,并记录成功和错误?
delayed_job is at http://github.com/collectiveidea/delayed_job
Can delayed_job have the ability to do cron task? Such as running a script every night at 1am. Or run a script every 1 hour.
If not, what are the suitable gems that can do that? And can it be monitored remotely using a browser, and have logging of success and error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我参与的一个项目尝试使用 DelayedJob 来安排未来的项目。太糟糕了。
相反,我建议您使用whenever gem:
http://github.com/javan/whenever
代码如下所示(来自 github)
这里有关如何使用的 RailsCast 视频它。
以及相应的 ASCIICast。
I worked on a project that tried to use DelayedJob to schedule future items. It sucked.
Instead I recommend you use the whenever gem:
http://github.com/javan/whenever
Code looks like this (from github)
Here's a RailsCast video on how to use it.
And the corresponding ASCIICast.
我认为 cron 是比 Delayed_job 更好的工具。我之前在一个项目中使用过它,它确实非常擅长在后台或在特定时间运行任务。但是,对于定期发生的重复任务,我认为 cron 是最好的工具。
查看每当(及其Railscast) 轻松安排可以运行 rake 任务(或 thor、shell 脚本或其他任何内容)的 cron 作业。您可以使用 rake 任务更新您的模型,然后使用某种仪表板控制器来查看各种状态。
I think cron is a better tool for this than delayed_job. I've used it in a project before, and it really excels at running at task in the background or at a particular time. But, for recurring tasks that happen at regular times, I think cron is the best tool.
Check out whenever (and its Railscast) to easily schedule cron jobs that can run rake tasks (or thor, or shell scripts, or anything else.) You can use the rake tasks to update your models and then have some sort of dashboard controller that looks at the various statuses.
您还可以使用 ClockWork gem:
https://github.com/adamwiggins/clockwork-rails-dj
Clockwork 作为单独的守护进程,可用于触发任何类型的作业,这些作业要么添加到作业排队系统,要么立即运行。
使用 Delayed_Job 发挥它的作用,即可以分布在多个节点(或不分布)的作业排队系统。
使用其他方法在正确的时间将作业添加到队列中。
我使用 rake(或 runner)/cron/whenever gem 来安排后台任务,但发现我的服务器负载非常高,因为我会不断受到 rake/runner 加载 Rails 环境的影响。
Delayed_Job 工作线程是保持运行的 Rails 守护进程,因此您不必在每次需要后台任务时不断启动 Rails。
You can also use the ClockWork gem:
https://github.com/adamwiggins/clockwork-rails-dj
Clockwork runs as a separate daemon and can be used to trigger jobs of any sort that either getting added to a job queueing system or run right away.
Use Delayed_Job for what it's good for, a job queueing system which can be distributed over multiple nodes (or not).
Use something else to add jobs to the queue at the right time.
I was using rake(or runner)/cron/whenever gem to schedule background tasks but was finding my server load was just so high because I would be getting hit constantly with rake/runner loading up the rails environment.
Delayed_Job workers are your rails daemons that stay running so you aren't constantly firing up Rails every time a background task is required.
每当工作都很棒。
我也喜欢
rufus-scheduler
然后在该文件中:
我最初发现这个帖子 这里
我已经尝试过了,效果很好。
更新
现在我回头看那个链接,它几乎是我想工作的唯一一家铁路公司。他们创造了许多宝石,并为社区做出了很多贡献。更不用说他们有一个庞大的团队!
Whenever works great.
I also like
rufus-scheduler
Then in that file:
I originally found this posted here
I've tried it and it works well.
update
Now that I look back at that link it's pretty much the only rails company that I would want to work for. They have made some many gems and add such much to the community. Not to mention they have a huge team!
我运行多个 crondelayed_jobs 以进行夜间统计和报告生成,并以一定的时间间隔进行数据报废。我是这样做的:
https://aaronvb.com/articles/循环延迟作业-with-cron.html
I run multiple cron delayed_jobs for nightly statistic and report generating and also for data scrapping at certain intervals. Here's how I do it:
https://aaronvb.com/articles/recurring-delayed-job-with-cron.html
我为此创建了一个 gem:
https://github.com/sellect/delayed_cron
它适用于 sidekiq 和目前已延迟作业。希望尽快添加resque。我知道这有点晚了,但它几乎完全符合您的要求。
I created a gem for this:
https://github.com/sellect/delayed_cron
It works with sidekiq and delayed_job currently. Looking to add resque soon. I know this is a bit late, but it does pretty much exactly what you were looking for.