Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     /** @var TaskInterface $task */
     foreach ($this->storage->findScheduled() as $task) {
         if (!$this->registry->has($task->getTaskName())) {
             $this->warning($this->getNoHandlerFoundMessage($task));
             continue;
         }
         $this->eventDispatcher->dispatch(Events::TASK_BEFORE, new TaskEvent($task));
         try {
             $result = $this->registry->run($task->getTaskName(), $task->getWorkload());
             $task->setResult($result);
             $task->setCompleted();
             $this->storage->persist($task);
             $this->eventDispatcher->dispatch(Events::TASK_PASSED, new TaskEvent($task));
         } catch (\Exception $ex) {
             // TODO set task failed. failed tasks, can be restarted by adding a flag to run command.
             $this->eventDispatcher->dispatch(Events::TASK_FAILED, new TaskFailedEvent($task, $ex));
             throw $ex;
         }
         $this->eventDispatcher->dispatch(Events::TASK_AFTER, new TaskEvent($task));
         // TODO move to event-dispatcher
         if ($task instanceof FrequentTaskInterface) {
             $task->scheduleNext($this);
         }
     }
 }
 public function testRun()
 {
     $this->assertEquals('daolkrow', $this->registry->run('test', 'workload'));
 }