我怎样才能在Heroku上安排'每周'工作? [英] How can I schedule a 'weekly' job on Heroku?

查看:99
本文介绍了我怎样才能在Heroku上安排'每周'工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在我想要一份每周工作

strong>,但调度程序插件不允许我每周选择一次。



有关如何完成此操作的任何建议:


  • 过去使用rufus调度程序,但它造成了一些问题,所以这不是一个选项。有关详细信息,请参见此处

  • 我正在考虑在日常工作中检查当前日期的事情。有没有人尝试过,并有反馈或知道问题的方法?

  • 其他想法非常感谢。



$ b

激活Heroku cron add-并在 app / lib / tasks

中添加 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 cron add-on, and add a cron.rake task in app/lib/tasks

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上安排'每周'工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆