Exemplo n.º 1
0
 /**
  * @param ContextInterface $context
  *
  * @throws FailureException if any of the tasks fail
  */
 public function run(ContextInterface $context)
 {
     $failures = false;
     $messages = array();
     $tasks = $this->tasks->filterByContext($context)->sortByPriority($this->grumPHP);
     $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_RUN, new RunnerEvent($tasks));
     foreach ($tasks as $task) {
         try {
             $this->eventDispatcher->dispatch(TaskEvents::TASK_RUN, new TaskEvent($task));
             $task->run($context);
             $this->eventDispatcher->dispatch(TaskEvents::TASK_COMPLETE, new TaskEvent($task));
         } catch (RuntimeException $e) {
             $this->eventDispatcher->dispatch(TaskEvents::TASK_FAILED, new TaskFailedEvent($task, $e));
             $messages[] = $e->getMessage();
             $failures = true;
             if ($this->grumPHP->stopOnFailure()) {
                 break;
             }
         }
     }
     if ($failures) {
         $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_FAILED, new RunnerFailedEvent($tasks, $messages));
         throw new FailureException(implode(PHP_EOL, $messages));
     }
     $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_COMPLETE, new RunnerEvent($tasks));
 }
Exemplo n.º 2
0
 /**
  * @param TaskInterface $task Task
  *
  * @return $this
  */
 public function addTask(TaskInterface $task)
 {
     if (!$this->tasks->contains($task)) {
         $this->tasks->add($task);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * @param ContextInterface $context
  *
  * @throws FailureException if any of the tasks fail
  */
 public function run(ContextInterface $context)
 {
     $failures = false;
     $messages = array();
     $tasks = $this->tasks->filterByContext($context);
     foreach ($tasks as $task) {
         try {
             $task->run($context);
         } catch (RuntimeException $e) {
             $failures = true;
             $messages[] = $e->getMessage();
         }
     }
     if ($failures) {
         throw new FailureException(implode(PHP_EOL, $messages));
     }
 }
Exemplo n.º 4
0
 /**
  * @param ContextInterface $context
  *
  * @return TaskResultCollection
  */
 public function run(ContextInterface $context)
 {
     $tasks = $this->tasks->filterByContext($context)->sortByPriority($this->grumPHP);
     $taskResults = new TaskResultCollection();
     $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_RUN, new RunnerEvent($tasks, $context, $taskResults));
     foreach ($tasks as $task) {
         try {
             $taskResult = $this->runTask($task, $context);
         } catch (RuntimeException $e) {
             $taskResult = TaskResult::createFailed($task, $context, $e->getMessage());
         }
         $taskResults->add($taskResult);
         if (!$taskResult->isPassed() && $taskResult->isBlocking() && $this->grumPHP->stopOnFailure()) {
             break;
         }
     }
     if ($taskResults->isFailed()) {
         $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_FAILED, new RunnerFailedEvent($tasks, $context, $taskResults));
         return $taskResults;
     }
     $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_COMPLETE, new RunnerEvent($tasks, $context, $taskResults));
     return $taskResults;
 }