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?