0

Magento Automatic backup I've been having trouble with for a while. Installed Scheduler timeline view and seen the error message "Missed" with;

exception 'Mage_Core_Exception' with message 'Too late for the schedule.' in /home/pctekcom/public_html/app/Mage.php:595
Stack trace:
#0 /home/pctekcom/public_html/app/code/core/Mage/Cron/Model/Observer.php(293): Mage::throwException('Too late for th...')
#1 /home/pctekcom/public_html/app/code/core/Mage/Cron/Model/Observer.php(72): Mage_Cron_Model_Observer->_processJob(Object(Aoe_Scheduler_Model_Schedule), Object(Mage_Core_Model_Config_Element))
#2 /home/pctekcom/public_html/app/code/core/Mage/Core/Model/App.php(1339): Mage_Cron_Model_Observer->dispatch(Object(Varien_Event_Observer))
#3 /home/pctekcom/public_html/app/code/core/Mage/Core/Model/App.php(1318): Mage_Core_Model_App->_callObserverMethod(Object(Zero1_Crondoctor_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#4 /home/pctekcom/public_html/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#5 /home/pctekcom/public_html/cron.php(77): Mage::dispatchEvent('default')
#6 {main}

I've tried with different times and weekly/daily with the same affect. A manual backup works (takes a long time though, many items) but Automatic fails with this same error message.

I posted this last week with no answer. Maybe this week someone might see and know whats wrong. Thanks

1 Answer 1

2

Reason 1: UTC timezone

Timezones can always be a bit of a headache when it comes to scheduled tasks and server locations. Magento stores it’s cron tasks in UTC, but checks the locale of your (admin) store to see if the time has already passed. Therefore it is advised to set the time of your store to UTC, but the time of your separate websites/store views respectively to their locale.

Reason 2: The 'missed if not run within' -parameter

If you want to know how Magento determines if a task is ‘too late for the schedule’ take a look at Mage_Cron_Model_Observer::_processJob(). This is the part of the code that is responsible for the message:

$scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60;
$now = time();
$time = strtotime($schedule->getScheduledAt());
if ($time > $now) {
    return;
}

...

if ($time < $now - $scheduleLifetime) {
    $errorStatus = Mage_Cron_Model_Schedule::STATUS_MISSED;
    Mage::throwException(Mage::helper('cron')->__('Too late for the schedule.'));
}

... 

// (execute the chain of tasks)

The self::XML_PATH_SCHEDULE_LIFETIME -parameter is the ‘missed if not run within’-value which is set in the configuration in 'System > Config > Advanced > System > Cron':

Cron (Scheduled Tasks)

The code itself is pretty self-explanatory:

  • It takes the time of the scheduled tasks.
  • If the time of the scheduled task is in the future it does nothing.
  • If the time of the scheduled task is in the past (=older than the current timestamp minus the 'missed if not run within'-value) it throws the error.
  • Otherwise it just runs the task as required.

Effectively, when the ‘missed if not run within’-parameter is set to 15 minutes, this means that if the scheduled task is older than now – 15 minutes, it will not run, but instead throw this error. Needless to say, when this value is lower than the time your cron runs (for example: if your cron runs every 5 minutes, but this value is set to 2 minutes), this will obviously throw this error.

You probably didn’t do this, but it is good to know this inner mechanic of how Magento handles crons. Especially the part that Magento checks the schedule prior before running any tasks. And in the next reason I’ll explain to you why:

Reason #3: External plugins

This is the part where I was pulling my hairs. My timezone was correct, my configuration was correct, but my cron schedule was still showing the ‘too late for the schedule’-message. So what was happening?

On further inspection, I noticed that there were some tasks from external plugins who where starting (the executed_at -column in the database revealed this), but were never finishing (the finished_at -column stayed NULL for these tasks). So something was preventing these tasks from being finished (probably causing a crash in PHP or something) and therefore stopping the entire chain of tasks!

The next logical thing that happened of course, was that after 3 tries (15 minutes later), the time for all the scheduled tasks that where further on in the chain all became too late. Too late for the schedule to be exactly. Up until the task that was causing the problems itself also became too late.

So how did I solve this?

Well, in my case I had to debug and fix the tasks of 2 external plugins that were throwing notices and warnings. For some reason even a notice or a warning (so not just an exception) caused my cron to fail silently. Perhaps the fact that I was on HHVM instead of PHP had something to do with this, but I’m not sure (yet).

In conclusion

After you did an investigation and it still not working. You can try increase your PHP memory_limit.

UPDATED

In AOE Scheduler I was seeing weird bars where it looked like a certain cron was running for a really long time but according to logs they were only running for a second or so. I checked in that cron and it had the code:

date_default_timezone_set('Australia/Brisbane');

The cron itself was overriding the Magento timezone which was causing following cron tasks to think they'd missed their chance to run..

Hope it helps.

2
  • nice explaination.... Commented Apr 19, 2016 at 6:53
  • Thankyou very very much for the explanation!! Was a good read and helped me for what I needed. Much appreciated Toan Nguyen
    – SixShields
    Commented Apr 20, 2016 at 5:48

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.