How can I schedule a 'weekly' job on Heroku?

前端 未结 5 1805
走了就别回头了
走了就别回头了 2020-12-24 08:49

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 schedul

5条回答
  •  忘掉有多难
    2020-12-24 08:49

    An alternate option using only shell code. Setup the Heroku scheduler hourly, and do a comparison against the date command:

    # setting the schedular to run hourly at *:30 is equivalent to the 
    # crondate: 30 8 * * 1
    if [ "$(date +%H)" = 08 ] && [ "$(date +%d)" = 01 ]; then YOUR_COMMAND ; fi 
    

    I've used this code to mimic cron in my local time zone:

    nz_hour="$(TZ=NZ date +%H)" ; nz_day="$(TZ=NZ date +%d)" ; if [ "$nz_hour" = 08 ] && [ "$nz_day" = 01 ]; then YOUR_COMMAND ; fi 
    

提交回复
热议问题