本文介绍了是Rails的“delayed_job”对于cron任务真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

delayed_job位于



delay_job能否执行cron任务?例如每天凌晨1点运行一个脚本。或每1小时运行一个脚本。



如果没有,什么是合适的宝石可以做到吗?可以使用浏览器远程监控,并记录成功和错误吗?

解决方案

使用DelayedJob安排未来的项目。



a href =http://github.com/javan/whenever =nofollow noreferrer> http://github.com/javan/whenever

代码看起来像这样(来自github)



每3.hours做
runMyModel.some_process
rakemy:rake:task
command usr / bin / my_great_command
end

每1.day,:at => '4:30 am'do
runnerMyModel.task_to_run_at_four_thirty_in_the_morning
end

every:hour do#许多快捷键可用::hour,:day,:month,:year ,:reboot
runnerSomeModel.ladeeda
end

every:sunday,:at => '12pm'do#使用一周中的任何一天或:周末,:weekday
runnerTask.do_something_great
end

RailsCast视频



以及相应的。


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?

解决方案

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)

  every 3.hours do
    runner "MyModel.some_process"
    rake "my:rake:task"
    command "/usr/bin/my_great_command"
  end

  every 1.day, :at => '4:30 am' do
    runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
  end

  every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
    runner "SomeModel.ladeeda"
  end

  every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
    runner "Task.do_something_great"
  end

Here's a RailsCast video on how to use it.

And the corresponding ASCIICast.

这篇关于是Rails的“delayed_job”对于cron任务真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:24