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

前端 未结 5 1789
走了就别回头了
走了就别回头了 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条回答
  •  萌比男神i
    2020-12-24 08:49

    As discussed over here, and using the above logic from Rob, here are the bash scripts broken down by a day of the week, once a month, and on a specific date.

    Run a task every Monday:

    if [ "$(date +%u)" = 1 ]; then MY_COMMAND; fi
    

    Run a task every 1st day in a month:

    if [ "$(date +%d)" = 01 ]; then MY_COMMAND; fi
    

    You could also run a job every year on December 24th:

    if [ "$(date +%m)" = 12 ] && [ "$(date +%d)" = 24 ]; then MY_COMMAND; fi
    

提交回复
热议问题