/** * Process due jobs. */ public function processJobs() { $maxExecutionEndTime = Customweb_Core_Util_System::getScriptExecutionEndTime(); $this->resetTimeoutJobs(); $schedules = $this->getPendingSchedules(); foreach ($schedules->getIterator() as $schedule) { /** * * @var $schedule Customweb_Subscription_Model_Schedule */ if ($this->isScheduleDue($schedule)) { // If we have only 10 seconds left until the server will kill the script, we return to give // the rest of the code the time to finish. if ($maxExecutionEndTime - time() < 10) { return; } try { if (!$schedule->tryLockJob()) { return; } $schedule->setExecutedAt(Mage::helper('customweb_subscription')->toDateString(Zend_Date::now()))->save(); $this->processJob($schedule); $schedule->setStatus(Customweb_Subscription_Model_Schedule::STATUS_SUCCESS)->setFinishedAt(Mage::helper('customweb_subscription')->toDateString(Zend_Date::now()))->save(); } catch (Exception $e) { Mage::logException($e); $schedule->setMessages($e->__toString()); $this->reschedule($schedule); } $schedule->save(); } } $this->cleanUp(); }
/** * @Cron() */ public function cleanUp() { $maxEndtime = Customweb_Core_Util_System::getScriptExecutionEndTime() - 4; // Remove all contexts which are not changed in the last 2 days and the state is not completed. $collection = Mage::getModel('saferpaycw/externalCheckoutContext')->getCollection()->addFieldToFilter('updated_on', array('to' => new Zend_Db_Expr('NOW() - INTERVAL 2 DAY')))->addFieldToFilter('state', array('neq' => 'completed'))->setCurPage(1)->setPageSize(40); foreach ($collection as $entity) { if ($maxEndtime > time()) { $entity->delete(); } else { break; } } }
public function cleanUp() { $maxEndtime = Customweb_Core_Util_System::getScriptExecutionEndTime() - 4; $where = '(updatedOn < NOW() - INTERVAL 2 MONTH AND authorizationStatus = "' . Customweb_Payment_Authorization_ITransaction::AUTHORIZATION_STATUS_FAILED . '") OR (updatedOn < NOW() - INTERVAL 6 MONTH AND authorizationStatus = "' . Customweb_Payment_Authorization_ITransaction::AUTHORIZATION_STATUS_PENDING . '" ) OR (updatedOn < NOW() - INTERVAL 1 MONTH AND (authorizationStatus = "" OR authorizationStatus IS NULL )) LIMIT 0,40'; $removable = $this->manager->searchPrimaryKey($this->transactionClassName, $where); foreach ($removable as $remove) { if ($maxEndtime > time()) { $this->manager->removeByPrimaryKey($this->transactionClassName, $remove); } else { break; } } }
public function cleanUp() { $maxEndtime = Customweb_Core_Util_System::getScriptExecutionEndTime() - 4; // Remove all contexts which are not changed in the last 2 days and the state is not completed. $where = 'updatedOn < NOW() - INTERVAL 2 DAY AND state != "completed" LIMIT 0,40'; $entities = $this->entityManager->search($this->contextEntityName, $where); foreach ($entities as $entity) { if ($maxEndtime > time()) { $this->entityManager->remove($entity); } else { break; } } }