问题描述
现在我想要一份每周工作
strong>,但调度程序插件不允许我每周选择一次。
有关如何完成此操作的任何建议:
$ b 中添加
cron.rake
任务b $ b
激活Heroku调度程序加载项,并在 app / lib / tasks中添加
scheduler.rake
任务
任务:your_weekly_task => :如果Time.now.friday,环境做
? #先前的答案:Date.today.wday == 5
#do something
end
end
你甚至可以定义你想要任务运行的日子; o)
(星期五为5)
编辑:顺便说一下,Cron已被弃用,Heroku建议切换到他们的Scheduler插件。尽管如此,这并没有改变每周工作的方法。
编辑2:根据来自sunkencity的反馈调整我的答案。
I have a Rails app deployed on Heroku with the Heroku scheduler add-on successfully working for daily jobs.
Now I want a weekly job, but the scheduler add-on does not allow me a weekly option.
Any suggestions on how I could accomplish this:
- I've tried using rufus-scheduler in the past but it caused me some problems, so that's not an option. See here for detail.
- I'm thinking of something along the lines of checking for current day within a daily job. Has anyone tried it and have feedback or know of issues with the approach?
- Other ideas much appreciated.
One approach would be the one of your 2nd bullet point:
Activate the Heroku scheduler add-on, and add a scheduler.rake
task in app/lib/tasks
task :your_weekly_task=> :environment do
if Time.now.friday? # previous answer: Date.today.wday == 5
#do something
end
end
You even have the luxury of defining the day you want your task to run ;o)(5 is for Friday)
EDIT: by the way, Cron is deprecated and Heroku recommends switching to their Scheduler add-on. This doesn't change the approach for a weekly job though.
EDIT2: adjustments to my answer based on feedback from sunkencity.
这篇关于我怎样才能在Heroku上安排'每周'工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!