How to make a cron job run during business hours o

2019-03-02 21:52发布

I've read the docs, but I'm scratching my head on how to do this. I want to run a cron job during business hours. So my cron.yaml would look something like:

cron:
- description: My Cool Cron Job 
  url: /myCoolCronJob.php 
  schedule: every 5 minutes from 06:00 to 19:00 every monday, tuesday, wednesday, thursday, friday
  timezone: America/Los_Angeles

That doesn't work, obviously. But it should give you an idea of what I want to do. How can I make this cron job run during business hours?

1条回答
叛逆
2楼-- · 2019-03-02 22:33

The Schedule format doesn't offer a combination between the high-frequency

every N (hours|mins|minutes) ["from" (time) "to" (time)]

and the low frequency

("every"|ordinal) (days) ["of" (monthspec)] (time)

The way to obtain what you desire is to:

  • configure the high frequency portion of the schedule in cron.yaml:

    schedule: every 5 minutes from 06:00 to 19:00

  • check the weekday condition inside the cron job itself, at the beginning and exiting without doing anything if the day of execution is Saturday or Sunday.

查看更多
登录 后发表回答