开发者

How can I space crons in 100 minute cycles?

I had to split some larger crons and an easy way was to just take the last two digits of the id. So id 10001 would run at the same time as 1,101,201,...1001,2001,etc.

Instead of a single cron taking hours t开发者_开发知识库o run, they now are split 100 times and run much more consistently.

However, how can I schedule a cron to run every 100 minutes, starting at x?

example:

php cron.cli 00   start at 12:01am and run every 100 minutes
php cron.cli 01   start at 12:01am
php cron.cli 02   start at 12:02am
     . . .
php cron.cli 99   start at 1:39am
php cron.cli 00   start at 1:40am [looping every 100 minutes]
php cron.cli 01   start at 1:41am

I need cron 01 to start at 12:01am, cron 02 to start at 12:02am and cron 99 to start at 1:39am. And every hundred seconds afterward, respectively.

Can you help?


I would only write one entry into the crontab file. The one command would start the cron.cli script and passing the current time as a parameter.

The cron-cli script then takes that parameter and creates the id in question out of it. That made, the file is much simpler to manage, as you won't mess the crontab file with soo many entries. And imagine your 100 steps become 200 steps or even more ... .

* * * * * php cron.cli $(date +\%R)


Assuming they don't have to run contiguously, a simple work-around is to let them run every 120 minutes, so you can specify even-numbered hours for jobs 00 to 59 (I'm guessing you start at 00, since you finish at 99.) and odd-numbered hours for jobs 61 to 99.

If you want a more even distribution, you could spread them out a little (skip minutes that are multiples of 6), so that jobs 00 to 49 fill up the first hour, and 50 to 99 fill up the second hour.


Luckily, if you write this out explicitly, you only need to specify one year's worth of cron entries, since:

How can I space crons in 100 minute cycles?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜