public function testRunTasksFailed() { $task = $this->createTask(); $executions = [$this->createTaskExecution($task, new \DateTime(), 'Test 1')->setStatus(TaskStatus::PLANNED), $this->createTaskExecution($task, new \DateTime(), 'Test 2')->setStatus(TaskStatus::PLANNED)]; $this->taskExecutionRepository->save($executions[0])->willReturnArgument(0)->shouldBeCalledTimes(2); $this->taskExecutionRepository->save($executions[1])->willReturnArgument(0)->shouldBeCalledTimes(2); $handler = $this->prophesize(TaskHandlerInterface::class); $handler->handle('Test 1')->willThrow(new \Exception()); $handler->handle('Test 2')->willReturn(strrev('Test 2')); $this->taskExecutionRepository->findScheduled()->willReturn($executions); $this->taskHandlerFactory->create(TestHandler::class)->willReturn($handler->reveal()); $this->initializeDispatcher($this->eventDispatcher, $executions[0], Events::TASK_FAILED); $this->initializeDispatcher($this->eventDispatcher, $executions[1]); $this->taskRunner->runTasks(); $this->assertLessThanOrEqual(new \DateTime(), $executions[0]->getStartTime()); $this->assertLessThanOrEqual(new \DateTime(), $executions[1]->getStartTime()); $this->assertLessThanOrEqual($executions[1]->getStartTime(), $executions[0]->getStartTime()); $this->assertLessThanOrEqual($executions[0]->getEndTime(), $executions[0]->getStartTime()); $this->assertLessThanOrEqual($executions[1]->getEndTime(), $executions[1]->getStartTime()); $this->assertGreaterThan(0, $executions[0]->getDuration()); $this->assertGreaterThan(0, $executions[1]->getDuration()); $this->assertNull($executions[0]->getResult()); $this->assertNotNull($executions[0]->getException()); $this->assertEquals(strrev('Test 2'), $executions[1]->getResult()); $this->assertNull($executions[1]->getException()); $this->assertEquals(TaskStatus::FAILED, $executions[0]->getStatus()); $this->assertEquals(TaskStatus::COMPLETED, $executions[1]->getStatus()); }
/** * Run scheduled tasks. * * @param Event $event */ public function run(Event $event) { $this->taskRunner->runTasks(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->runner->runTasks(); $this->scheduler->scheduleTasks(); }