I have a difficult time when the Cron task runs once a day at a given time. Here is what I have in my module configuration:
<crontab>
<jobs>
<sorting_flushcache>
<schedule><cron_expr>0 16 * * *</cron_expr></schedule>
<run><model>sorting/observer::flushProductCacheCron</model></run>
</sorting_flushcache>
</jobs>
</crontab>
From what I know about cron, this should work at 17:00 in my local time zone. However, it NEVER works. If I set cron_expr to * 16 * * *, it schedules the task every minute for the whole hour (as expected).
I drew the code and I think I found the problem, but I donβt know enough about cron planning and how this should really work, so I hope someone can help me figure out what is wrong and how to do my job .
Mage_Cron_Model_Schedule is the brain of the beast. When the cron.php script is invoked by the crontab server schedule, it dispatches an event that this class catches and does its job. Among other things, he pulls in the configuration and tries to schedule upcoming cron jobs. Inside, public function trySchedule($time)it calls matchCronExpression, passing it a piece of the cron expression in question along with the current time value corresponding to this part of the cron expression. For example, it compares the first part of cron_expr (part of minutes) with the protocols of the current timestamp. At the end of the function, matchCronExpressionit returns the following logical value:
return ($num>=$from) && ($num<=$to) && ($num%$mod===0);
cron_expr - 0 16 * * *. - */5 stuff , , , . , true, , cron script , .
, cron, . , , cron script? , - ... - ?
- CRON CONFIG INFO -
generate schedules every: 5
schedule ahead for: 10
missed if not run within: 20
success history lifetime: 60
failure history lifetime: 600