Rails在特定时间段内执行Cron作业或Rake任务 [英] Rails Execute Cron Job or Rake task for specific time period
问题描述
我想在特定时间段执行一些任务。假设我想在上午6点到上午9点之间每半小时执行cronjob或一些耙子任务。所以脚本将获得执行6,6,30,7,7:30 ...并在9处执行。
I want to execute some task for a specific time period. Lets say I want to execute cronjob or some rake task between 6am to 9am for every half an hour. So script will get execute 6, 6:30, 7, 7:30... and last at 9.
你能不能给我一些建议,这样做与Rails。
Can you please give me some suggestion that how I can do this with Rails.
不要告诉我计划个人任务6,6,30,7 ..时间段。
Don't tell me that schedule individual task for 6, 6:30, 7.. time period.
ANS
我找到的最简单的方法是使用每当gem和添加cronjob时间如下。
ANS
Simplest way I have found is to use whenever gem and adding cronjob time as below.
every '*/30 6-9 * * *' do
runner "Model.method"
end
推荐答案
我喜欢使用delayed_job来执行计划任务 - https://github.com/collectiveidea/delayed_job
I like to use delayed_job for scheduled tasks - https://github.com/collectiveidea/delayed_job
添加作业时,您可以指定run_at属性
When you enque a job you can specify the run_at attribute
这篇关于Rails在特定时间段内执行Cron作业或Rake任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!