Cron Job Runs Twice – How to Fix Daily Cron Job Issue

cron

I read this post explaining the details of the System->Cron settings in the Magento admin section, but I am still not clear on how the settings all affect the execution of my cron job.

I my system cron tab is set to execute cron.php every 5 minutes:

*/5 * * * * php -f /mysite/cron.php

I configured a job within a custom module's config.xml file to run one time per day:

<schedule>
    <cron_expr>30 10 * * *</cron_expr>
</schedule>

And my admin settings are:
System->Configuration->System->Cron

The cron job I am interested in runs first at 17:30 and then again at 17:35.

The record of this job in cron_schedule is:

cron_schedule

It looks like the problem is that Generate Schedules Every runs twice within the Schedule Ahead for time frame and sets the job twice, but the descriptions I have read on the admin settings led to to think that having Schedule Ahead for be a greater time frame than Generate Schedules Every was desirable.

What do I need to change in my admin settings?

Best Answer

You should actually be using the cron.sh script found packaged with magento. This does a ps | grep call to make sure the Magento cron isn't already running. If it is then it doesn't run. If you do this then you will never have worry about cron tasks overlapping.

Your cron setup would look something like this.

*/5 * * * * /yoursite/cron.sh

If you package this up with the AOE_Scheduler extension you'll be onto a winner.

Related Topic