0

I am developing a custom module and in that I am using Cron to disable the status of notifications.

I have written this code in config.xml

<crontab>
    <jobs>
        <disable_notifications>
            <schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
            <run><model>notifications/cronjobs::disableNotifications</model></run>
        </disable_notifications>
        <test>
            <schedule><cron_expr>*/1 * * * *</cron_expr></schedule>
            <run><model>notifications/cronjobs::test</model></run>
        </test>
    </jobs>
</crontab>

All other crons expect this two are working fine and getting executed as scheduled but my crons are getting scheduled in database table 'cron_schedule' but the status updates in missed. enter image description here

Please let me know the solution. I am stuck with this problem from 3 days.

  • Can you provide the Exception caught pls? – Julien Lachal Nov 18 '16 at 11:07
  • I am getting this message everytime when it is missed. exception 'Mage_Core_Exception' with message 'Too late for the schedule.' – Gaurav Agrawal Nov 18 '16 at 11:07
2

AFAIK, cron jobs are marked as missed based on the configuration under System > Configuration > Cron > Missed if not run within field.

I had the problem once where the cron was running once per hour, and that value was set to 15 minutes and thus a lot of jobs were marked as missed.

I suggest you ensure your cron runs every 5 minutes as suggested by the Magento documentation and if you can't do that, maybe update that configuration according to your configuration.

Update

According to your database table, it seems like those cronjobs generate an exception as you can see from the exception column: exception Mage_Core_Exception with message Too... . I'm pretty sure that's the root cause of your problem. Open one of those rows and find the full exception. Fixing the exception would most likely fix your problem.

  • I have configured cron to run after every 5 minutes and I have also configured System > Configuration > Cron > Missed if not run within field. But both of them together didn't worked for me. Can you suggest any other option? – Gaurav Agrawal Nov 18 '16 at 10:59
  • @GauravAgrawal yes see my updated answer – Raphael at Digital Pianism Nov 18 '16 at 11:04
  • It shows exception: exception 'Mage_Core_Exception' with message 'Too late for the schedule.' in /var/www/html/magento/app/Mage.php:595. – Gaurav Agrawal Nov 18 '16 at 11:37
  • @GauravAgrawal well yeah that's the error that matches the description I gave you first. You definitely have a problem with your cron. Double check how your cron is configured on your server – Raphael at Digital Pianism Nov 18 '16 at 11:38
  • All the default cronjobs in magento like: newsletter_send_all, core_email_queue_send_all are executed successfully in that table. – Gaurav Agrawal Nov 18 '16 at 11:41
0

Make sure your config for system/cron/schedule_lifetime is at least as small as your "fastest" cron.

In app/code/core/Mage/Cron/Model/Observer you can find the relevant code:

$scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60;
$now = time();
[...]
$time = strtotime($schedule->getScheduledAt());
[...]
if ($time < $now - $scheduleLifetime) {
    $errorStatus = Mage_Cron_Model_Schedule::STATUS_MISSED;
    Mage::throwException(Mage::helper('cron')->__('Too late for the schedule.'));
}

I'd also make sure your crontab executes cron.php (or cron.sh) in Magento's root folder, at least every minute since your notifications/cronjobs::test cron is supposed to run every minute.

  • What do you mean about this: Make sure your config for system/cron/schedule_lifetime is at least as small as your "fastest" cron. – Gaurav Agrawal Nov 18 '16 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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