/**
  * 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;
         }
     }
 }
Exemple #5
0
 /**
  * This method converts a given input stream into a local file if required and return the
  * path to the local file.
  *
  * @param Customweb_Core_Stream_IInput $inputStream
  */
 public static function getLocalFilePath(Customweb_Core_Stream_IInput $inputStream)
 {
     // In case we get a file input stream, we can simply return the path of the
     // file.
     if ($inputStream instanceof Customweb_Core_Stream_Input_File) {
         return $inputStream->getFilePath();
     }
     $tempDir = Customweb_Core_Util_System::getTemporaryDirPath() . self::TEMP_PATH_PREFIX;
     if (!file_exists($tempDir)) {
         mkdir($tempDir, 0770, true);
     }
     // Make sure we get a identifier which does not cause any issues on file system:
     $fileName = sha1($inputStream->getSystemIdentifier());
     if (preg_match('/^[0-9]/i', $fileName)) {
         $fileName = 'd' . $fileName;
     }
     $output = new Customweb_Core_Stream_Output_File($tempDir . '/' . $fileName);
     $output->writeStream($inputStream);
     return $output->getFilePath();
 }
 public static function setDefaultDateFormat($format)
 {
     self::$defaultDateFormat = $format;
 }