Exemplo n.º 1
0
 /**
  * Execute tasks in loop
  */
 protected function loopTasks()
 {
     do {
         // Try getting the next task and execute it
         // If there are no more tasks to execute, an exception is thrown by \TYPO3\CMS\Scheduler\Scheduler::fetchTask()
         try {
             /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask */
             $task = $this->scheduler->fetchTask();
             try {
                 $this->scheduler->executeTask($task);
             } catch (\Exception $e) {
                 // We ignore any exception that may have been thrown during execution,
                 // as this is a background process.
                 // The exception message has been recorded to the database anyway
                 continue;
             }
         } catch (\OutOfBoundsException $e) {
             $this->hasTask = false;
         } catch (\UnexpectedValueException $e) {
             continue;
         }
     } while ($this->hasTask);
     // Record the run in the system registry
     $this->scheduler->recordLastRun();
 }
Exemplo n.º 2
0
 /**
  * Wraps the executeTask method
  *
  * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task The task to execute
  * @return boolean Whether the task was saved successfully to the database or not
  * @throws \Exception
  */
 public function executeTask(\TYPO3\CMS\Scheduler\Task\AbstractTask $task)
 {
     $taskUid = $task->getTaskUid();
     // log start
     $logUid = $this->logStart($taskUid);
     $failure = null;
     try {
         $result = parent::executeTask($task);
     } catch (\Exception $e) {
         $failure = $e;
     }
     if ($result || $failure) {
         $returnMessage = '';
         if ($task instanceof \AOE\SchedulerTimeline\Interfaces\ReturnMessage || is_callable(array($task, 'getReturnMessage'))) {
             $returnMessage = $task->getReturnMessage();
         }
         // log end
         $this->logEnd($logUid, $failure, $returnMessage);
     } else {
         // task was not executed, because another task was running
         // and multiple execution is not allowed for this task
         $this->removeLog($logUid);
     }
     if ($failure instanceof \Exception) {
         throw $failure;
     }
     return $result;
 }
 /**
  * Execute a single task
  *
  * @param int $taskId
  * @param bool $forceExecution
  */
 protected function executeSingleTask($taskId, $forceExecution)
 {
     // Force the execution of the task even if it is disabled or no execution scheduled
     if ($forceExecution) {
         $task = $this->scheduler->fetchTask($taskId);
     } else {
         $whereClause = 'uid = ' . (int) $taskId . ' AND nextexecution != 0 AND nextexecution <= ' . (int) $GLOBALS['EXEC_TIME'];
         list($task) = $this->scheduler->fetchTasksWithCondition($whereClause);
     }
     if ($this->scheduler->isValidTaskObject($task)) {
         try {
             $this->scheduler->executeTask($task);
         } catch (\Exception $e) {
         }
         // Record the run in the system registry
         $this->scheduler->recordLastRun('cli-by-id');
     }
 }