我正在写一个Rake任务。我想在每个月的晚上11点触发它。
如何使用Ruby on Rails中的Whenever gem计划这个?
我的rake任务位于以下位置:app / lib / tasks / my_task.rake
{{1}}
答案 0 :(得分:2)
我不认为这个月的最后一天是#34;"但是你总是可以在块中添加额外的if
测试:
every :sunday, :at => '11pm' do
#if the month is different a week from now, we must be in the last
#sunday of the month
if Time.now.month != 1.week.from_now.month
rake "my:rake:task"
end
end
因此,这个预定的代码将在每个星期天运行,但是如果时间满足其他条件,它将继续调用rake任务。