/**
  * @param Mage_Cron_Model_Schedule $schedule
  * @return Varien_Object
  */
 public function getStartingIn(Mage_Cron_Model_Schedule $schedule)
 {
     $schedTime = $schedule->getScheduledAt();
     if ($schedTime == '0000-00-00 00:00:00' or $schedTime == '') {
         $runtime = new Varien_Object();
         $runtime->setHours(0);
         $runtime->setMinutes(0);
         $runtime->setSeconds(0);
         $runtime->setToString('0h 0m 0s');
         return $runtime;
     }
     // Calc Time interval till Exec
     $starttime = strtotime($schedTime) - strtotime(now());
     $prefix = '+';
     if ($starttime < 0) {
         $prefix = '-';
         $starttime *= -1;
     }
     $runtimeSec = $starttime % 60;
     $runtimeMin = (int) ($starttime / 60) % 60;
     $runtimeHour = (int) ($starttime / 3600);
     $runtime = new Varien_Object();
     $runtime->setHours($runtimeHour);
     $runtime->setMinutes($runtimeMin);
     $runtime->setSeconds($runtimeSec);
     $runtime->setPrefix($prefix);
     $runtime->setToString($runtimeHour . 'h ' . $runtimeMin . 'm ' . $runtimeSec . 's');
     return $runtime;
 }
Beispiel #2
0
 /**
  * Process cron task
  *
  * @param Mage_Cron_Model_Schedule $schedule
  * @param $jobConfig
  * @param bool $isAlways
  * @return Mage_Cron_Model_Observer
  */
 protected function _processJob($schedule, $jobConfig, $isAlways = false)
 {
     $runConfig = $jobConfig->run;
     if (!$isAlways) {
         $scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60;
         $now = time();
         $time = strtotime($schedule->getScheduledAt());
         if ($time > $now) {
             return;
         }
     }
     $errorStatus = Mage_Cron_Model_Schedule::STATUS_ERROR;
     try {
         if (!$isAlways) {
             if ($time < $now - $scheduleLifetime) {
                 $errorStatus = Mage_Cron_Model_Schedule::STATUS_MISSED;
                 Mage::throwException(Mage::helper('cron')->__('Too late for the schedule.'));
             }
         }
         // Aoe_Scheduler: stuff from the original method was removed and refactored into the schedule module
         /* @var $schedule Aoe_Scheduler_Model_Schedule */
         $schedule->runNow(!$isAlways);
     } catch (Exception $e) {
         $schedule->setStatus($errorStatus)->setMessages($e->__toString());
         // Aoe_Scheduler: additional handling:
         Mage::dispatchEvent('cron_' . $schedule->getJobCode() . '_exception', array('schedule' => $schedule, 'exception' => $e));
         Mage::dispatchEvent('cron_exception', array('schedule' => $schedule, 'exception' => $e));
         Mage::helper('aoe_scheduler')->sendErrorMail($schedule, $e->__toString());
     }
     $schedule->save();
     return $this;
 }
Beispiel #3
0
 /**
  * Process cron task
  *
  * @param Mage_Cron_Model_Schedule $schedule
  * @param $jobConfig
  * @param bool $isAlways
  * @return Mage_Cron_Model_Observer
  */
 protected function _processJob($schedule, $jobConfig, $isAlways = false)
 {
     $runConfig = $jobConfig->run;
     if (!$isAlways) {
         $scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60;
         $now = time();
         $time = strtotime($schedule->getScheduledAt());
         if ($time > $now) {
             return;
         }
     }
     $errorStatus = Mage_Cron_Model_Schedule::STATUS_ERROR;
     try {
         if (!$isAlways) {
             if ($time < $now - $scheduleLifetime) {
                 $errorStatus = Mage_Cron_Model_Schedule::STATUS_MISSED;
                 Mage::throwException(Mage::helper('cron')->__('Too late for the schedule.'));
             }
         }
         if ($runConfig->model) {
             if (!preg_match(self::REGEX_RUN_MODEL, (string) $runConfig->model, $run)) {
                 Mage::throwException(Mage::helper('cron')->__('Invalid model/method definition, expecting "model/class::method".'));
             }
             if (!($model = Mage::getModel($run[1])) || !method_exists($model, $run[2])) {
                 Mage::throwException(Mage::helper('cron')->__('Invalid callback: %s::%s does not exist', $run[1], $run[2]));
             }
             $callback = array($model, $run[2]);
             $arguments = array($schedule);
         }
         if (empty($callback)) {
             Mage::throwException(Mage::helper('cron')->__('No callbacks found'));
         }
         if (!$isAlways) {
             if (!$schedule->tryLockJob()) {
                 // another cron started this job intermittently, so skip it
                 return;
             }
             /**
                             though running status is set in tryLockJob we must set it here because the object
                             was loaded with a pending status and will set it back to pending if we don't set it here
             */
             //$schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_RUNNING);
         }
         $schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', time()))->save();
         call_user_func_array($callback, $arguments);
         $schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS)->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
     } catch (Exception $e) {
         $schedule->setStatus($errorStatus)->setMessages($e->__toString());
     }
     $schedule->save();
     return $this;
 }