1

I am having a very unusual issue at the moment with a cron task not working. In the table cron_schedule, it marks the executed_at time but never a finished_at time.

What makes this unusual is that I can get this to work fine, by placing a Mage::log() in the code.

DOESN'T WORK

function exportNewOrders()
{
    if( ! Mage::helper('warehouse/sales')->isExportEnabled() || ! Mage::helper('warehouse')->shouldRunCronJob('orders_export')) return;

    $_collection = $this->getOrdersCreatedSinceLastExport();

    // Don't generate xml if no new orders found
    if( ! count($_collection)) return;

    $_csv = Mage::getModel('warehouse/csv_order_export');

    foreach( $_collection as $_order )
    {
        $_csv->addOrder($_order);
    }
    $filename = Mage::helper('warehouse/file')->getFilename('orderexport');

    $result = $_csv->saveCsv($filename);

    if(!$result)
    {
        $this->getDebugHelper()->log( $this->getHelper()->__( 'Unable to write orders export to %s - writing error', $filename ));
    }
    else
    {
        $this->getDebugHelper()->log( $this->getHelper()->__( 'Wrote orders export to %s', $filename ));
        $this->setLastDate('sales_last_export');
        Mage::helper('warehouse/file')->setLastFileId(Mage::helper('warehouse/file')->getLastFileId() + 1);
    }

    return $this;
}

DOES WORK

function exportNewOrders()
{
    if( ! Mage::helper('warehouse/sales')->isExportEnabled() || ! Mage::helper('warehouse')->shouldRunCronJob('orders_export')) return;

    $_collection = $this->getOrdersCreatedSinceLastExport();
    Mage::log('hello', null, 'lu.log', true); //SEE THIS LINE

    // Don't generate xml if no new orders found
    if( ! count($_collection)) return;

    $_csv = Mage::getModel('warehouse/csv_order_export');

    foreach( $_collection as $_order )
    {
        $_csv->addOrder($_order);
    }
    $filename = Mage::helper('warehouse/file')->getFilename('orderexport');

    $result = $_csv->saveCsv($filename);

    if(!$result)
    {
        $this->getDebugHelper()->log( $this->getHelper()->__( 'Unable to write orders export to %s - writing error', $filename ));
    }
    else
    {
        $this->getDebugHelper()->log( $this->getHelper()->__( 'Wrote orders export to %s', $filename ));
        $this->setLastDate('sales_last_export');
        Mage::helper('warehouse/file')->setLastFileId(Mage::helper('warehouse/file')->getLastFileId() + 1);
    }

    return $this;
}

As you can see I am doing no extra logic, except for this log, however this now allows the cron task to complete and gives a finished_at time. I have replicated this 100% with several tests.

Anyone come across something similar? Any idea why this is happening?

5
  • 1
    Can it may be that the cron has different permissions and isn't allowed to write the log file and therefor crashing? Try running the script from the shell, does that offer some insight? Commented Sep 4, 2013 at 11:16
  • How to you call the cron? Is it executed automatically or manually via cron.sh? Does that make a difference? Commented Sep 4, 2013 at 11:32
  • ecomus.co.uk/magento-running-a-cron-job-manually Can you try to run your cron manually ? But this is really weird I have to say. Commented Sep 4, 2013 at 11:45
  • If the finsihed_at time is never set and the cron stays in a "running" status, it typically means it's dying due to a PHP level error. Check your PHP error logs.
    – davidalger
    Commented Sep 4, 2013 at 14:21
  • Are all the standard Magento Crons working and showing a finish time? Do you clean up the failed cron jobs?
    – kab8609
    Commented Sep 4, 2013 at 18:08

1 Answer 1

1

A Cron Job with no finished_at time, it probably never finished.

You should find something in your error logs.

Also it helps to use the module http://www.magentocommerce.com/magento-connect/aoe-scheduler.html to debug, as it allows to call your cron directly from cli via:
php shell/scheduler.php -action runNow -code productimporter_import_xml

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.