Esempio n. 1
0
 /**
  * Returns the list of the task names.
  *
  * @return string[]
  */
 public function getTaskList()
 {
     $tasks = $this->loader->loadTasks();
     return array_map(function (Task $task) {
         return $task->getName();
     }, $tasks);
 }
Esempio n. 2
0
 /**
  * Executes tasks that are scheduled to run, then reschedules them.
  *
  * @return array An array describing the results of scheduled task execution. Each element
  *               in the array will have the following format:
  *
  *               ```
  *               array(
  *                   'task' => 'task name',
  *                   'output' => '... task output ...'
  *               )
  *               ```
  */
 public function run()
 {
     $tasks = $this->loader->loadTasks();
     $this->logger->debug('{count} scheduled tasks loaded', array('count' => count($tasks)));
     // remove from timetable tasks that are not active anymore
     $this->timetable->removeInactiveTasks($tasks);
     $this->logger->info("Starting Scheduled tasks... ");
     // for every priority level, starting with the highest and concluding with the lowest
     $executionResults = array();
     for ($priority = Task::HIGHEST_PRIORITY; $priority <= Task::LOWEST_PRIORITY; ++$priority) {
         $this->logger->debug("Executing tasks with priority {priority}:", array('priority' => $priority));
         // loop through each task
         foreach ($tasks as $task) {
             // if the task does not have the current priority level, don't execute it yet
             if ($task->getPriority() != $priority) {
                 continue;
             }
             $taskName = $task->getName();
             $shouldExecuteTask = $this->timetable->shouldExecuteTask($taskName);
             if ($this->timetable->taskShouldBeRescheduled($taskName)) {
                 $rescheduledDate = $this->timetable->rescheduleTask($task);
                 $this->logger->debug("Task {task} is scheduled to run again for {date}.", array('task' => $taskName, 'date' => $rescheduledDate));
             }
             if ($shouldExecuteTask) {
                 $this->logger->info("Scheduler: executing task {taskName}...", array('taskName' => $taskName));
                 $timer = new Timer();
                 $this->isRunningTask = true;
                 $message = $this->executeTask($task);
                 $this->isRunningTask = false;
                 $this->logger->info("Scheduler: finished. {timeElapsed}", array('taskName' => $taskName, 'timeElapsed' => $timer));
                 $executionResults[] = array('task' => $taskName, 'output' => $message);
             }
         }
     }
     $this->logger->info("done");
     return $executionResults;
 }