1

Just a little problem which isn't blocking anything but still anoying.

I have created 2 modules triggered through a cron task. In both case, the module works fine, the cron tasks are scheduled correctly and the method called is executed. The problem is, if I look in the database (table cron_schedule), I can see that the scheduled_at and executed_at columns are set with dates, but the finished_at column is never filled. The cron task then ends in error because it reaches the time to live.

Any idea why it does that ?

Here's some code:

app/code/local/MyPackage/MyModule/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <MyPackage_MyModule>
            <version>1.0</version>
        </MyPackage_MyModule>
    </modules>

    <global>
        <blocks>
            <myModule>
                <class>MyPackage_MyModule_Block</class>
            </myModule>
        </blocks>

        <helpers>
            <myModule>
                <class>MyPackage_MyModule_Helper</class>
            </myModule>
        </helpers>

        <models>
            <myModule>
                <class>MyPackage_MyModule_Model</class>
            </myModule>
        </models>
    </global>

    <crontab>
        <jobs>
            <myPackage_myModule>
                <schedule><cron_expr>0 9 * * *</cron_expr></schedule>
                <run><model>myModule/observer::processReport</model></run>
            </myPackage_myModule>
        </jobs>
    </crontab>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <MyPackage_MyModule after="Mage_Adminhtml">MyPackage_MyModule_Adminhtml</MyPackage_MyModule>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <myModule>
                                            <title>orders report</title>
                                        </myModule>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

I don't display the observer because it's a little big and it works. If you still need it I can add it later.

Thanks

1

The most common cause of Magento's cron jobs never ending (resulting in a "too late for the schedule" error) is the cron job logic exiting without returning the control flow back to Magento. For example, it could be a PHP fatal error somewhere in the cron job logic, or it could be an exit or die call, etc.

This causes the cron job to silently fail each time, eventually becoming too late for the schedule, at which point Magento will happily reschedule (only to fail yet again).

Check your PHP error log for any fatal errors. You can easily check for syntax errors with php -l file.php. Also check your code for any references to exit, die, etc.

If that's not the case, you'll need to provide some more details regarding the actual cron job.

  • 1
    It doesn't have to be an error, I've seen cron modules that call exit which not only causes this behavior but any task scheduled in the same run but later in order never gets run. – Melvyn May 6 '15 at 17:58
  • @Melvyn Oh yeah, good point. Anything that causes the code to skip Magento's cleanup logic will do this. – Agop May 6 '15 at 18:41

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.