0

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?

3 Answers 3

1

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.

1
1

My advice would be to install AOEScheduler from http://www.magentocommerce.com/magento-connect/aoe-scheduler.html. It's free, doesn't appear to be that intensive but gives you a huge amount of insight into what your cron jobs are / are not doing. Crucially it will also display what's in your scheduler.

1
  • I do want to check this extension out. I was hesitant to add it for this one instance, but now I see why it exists. The Magento cron system takes some time to understand. Commented May 7, 2015 at 22:49
1

TL;DR - Check the server process list ps -A | grep cron or ps -A | grep crond to make sure cron isn't running more than once.

I recently had a cron task running twice that was very intensive to run. The task would generate a running log file show its progress (it would usually take 15-20 minutes to finish).

While watching the log file, I would notice the progress start over from the beginning but then continue updating the first task's progress, so I would see something like:

Items 1-500 -- done
Items 501-1000 -- done
Items 1001-1500 -- done
Items 1-500 -- done
Items 1501-2000 -- done
Items 501-1000 - done

Clearly the tasks were overlapping each other. I had checked all my cron settings to make sure it wasn't actually getting scheduled a second time before the first task ended. The task was set to run once per day and nothing in the schedules suggested that it was running more than that.

I started sniffing around the server and checking cron logs there. Then, I checked the process list: ps -A | grep cron and lo and behold there were three or four cron processes listed. Somewhere along the lines, the server people that "manage" the server (they do a horrible job) had mucked around in WHM or CPanel and added a bunch of cron tasks and not bothered to tell anyone. I'm not sure what happened but after they did this was when the duplicated cron tasks showed up.

1
  • This is exactly the situation I was having only the permissions for my user are so restricted that ps -A shows only my processes. I disabled my user's crontab and verified that the process is now getting scheduled only once. Thank you! Commented May 7, 2015 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.