I want to import products using cronjob. But issue is that when import job runs twice at the same time. How can I protect from these? I try to do this:
private function isImportAlreadyRunning()
{
$isRunning = false;
$cronSchecduleCollection = Mage::getModel('cron/schedule')->getCollection()
->addFieldToSelect(array('job_code', 'status'))
->addFieldToFilter('job_code', array('eq' => 'my_import_products'))
->addFieldToFilter('status', array('eq' => 'pending'))
->addFieldToFilter('executed_at', array('neq' => 'NULL'))
->load();
Mage::log('Cron size: ' .$cronSchecduleCollection->getSize());
if($cronSchecduleCollection->getSize() > 1)
{
$isRunning = true;
}
return $isRunning;
}
But these doesn't work because $cronSchecduleCollection->getSize() is equals 1, even if I run 2 process simultaneously. Class is singleton because it belongs to Helper.