Esempio n. 1
0
 /**
  * Logs cronjob exec success or failure.
  * 
  * @param	wcf\data\cronjob\CronjobEditor		$logEditor
  * @param	wcf\system\exception\SystemException	$exception
  */
 protected function logResult(CronjobLogEditor $logEditor, SystemException $exception = null)
 {
     if ($exception !== null) {
         $errString = implode("\n", array($exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString()));
         $logEditor->update(array('success' => 0, 'error' => $errString));
     } else {
         $logEditor->update(array('success' => 1));
     }
 }
Esempio n. 2
0
 /**
  * Deletes the entire cronjob log.
  */
 public function clearAll()
 {
     CronjobLogEditor::clearLogs();
 }
Esempio n. 3
0
 /**
  * Executes cronjobs.
  */
 public function execute()
 {
     $return = array();
     foreach ($this->objects as $key => $cronjob) {
         // skip jobs that are already being processed
         if ($cronjob->state == Cronjob::PENDING || $cronjob->state == Cronjob::EXECUTING) {
             unset($this->objects[$key]);
             continue;
         }
         // mark them as pending
         $cronjob->update(array('state' => Cronjob::PENDING));
     }
     foreach ($this->objects as $cronjob) {
         // it now time for executing
         $cronjob->update(array('state' => Cronjob::EXECUTING));
         $className = $cronjob->className;
         $executable = new $className();
         // execute cronjob
         $error = '';
         try {
             $executable->execute(new Cronjob($cronjob->cronjobID));
         } catch (\Exception $e) {
             $error = $e->getMessage();
         }
         CronjobLogEditor::create(array('cronjobID' => $cronjob->cronjobID, 'execTime' => TIME_NOW, 'success' => (int) ($error == ''), 'error' => $error));
         // calculate next exec-time
         $nextExec = $cronjob->getNextExec();
         $cronjob->update(array('nextExec' => $nextExec, 'afterNextExec' => $cronjob->getNextExec($nextExec + 120)));
         // build the return value
         $dateTime = DateUtil::getDateTimeByTimestamp($nextExec);
         $return[$cronjob->cronjobID] = array('time' => $nextExec, 'formatted' => str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat'))));
         // we are finished
         $cronjob->update(array('state' => Cronjob::READY));
     }
     return $return;
 }
Esempio n. 4
0
 /**
  * Executes cronjobs.
  */
 public function execute()
 {
     $return = array();
     foreach ($this->objects as $key => $cronjob) {
         // mark them as pending
         $cronjob->update(array('state' => Cronjob::PENDING));
     }
     foreach ($this->objects as $cronjob) {
         // it now time for executing
         $cronjob->update(array('state' => Cronjob::EXECUTING));
         $className = $cronjob->className;
         $executable = new $className();
         // execute cronjob
         $exception = null;
         try {
             $executable->execute(new Cronjob($cronjob->cronjobID));
         } catch (\Exception $exception) {
         }
         CronjobLogEditor::create(array('cronjobID' => $cronjob->cronjobID, 'execTime' => TIME_NOW, 'success' => $exception ? 0 : 1, 'error' => $exception ? $exception->getMessage() : ''));
         // calculate next exec-time
         $nextExec = $cronjob->getNextExec();
         $data = array('lastExec' => TIME_NOW, 'nextExec' => $nextExec, 'afterNextExec' => $cronjob->getNextExec($nextExec + 120));
         // cronjob failed
         if ($exception) {
             if ($cronjob->failCount < Cronjob::MAX_FAIL_COUNT) {
                 $data['failCount'] = $cronjob->failCount + 1;
             }
             // cronjob failed too often: disable it
             if ($cronjob->failCount + 1 == Cronjob::MAX_FAIL_COUNT) {
                 $data['isDisabled'] = 1;
             }
         } else {
             $data['failCount'] = 0;
             // if cronjob has been disabled because of too many
             // failed executions, enable it again
             if ($cronjob->failCount == Cronjob::MAX_FAIL_COUNT && $cronjob->isDisabled) {
                 $data['isDisabled'] = 0;
             }
         }
         $cronjob->update($data);
         // build the return value
         if ($exception === null && !$cronjob->isDisabled) {
             $dateTime = DateUtil::getDateTimeByTimestamp($nextExec);
             $return[$cronjob->cronjobID] = array('time' => $nextExec, 'formatted' => str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat'))));
         }
         // we are finished
         $cronjob->update(array('state' => Cronjob::READY));
         // throw exception again to show error message
         if ($exception) {
             throw $exception;
         }
     }
     return $return;
 }