Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function addTask(TaskInterface $task)
 {
     $this->eventDispatcher->dispatch(Events::TASK_CREATE, new TaskEvent($task));
     $this->taskRepository->save($task);
     $this->scheduleTask($task);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Create new task.
  *
  * @param string $workload
  * @param CronExpression $cronExpression
  * @param string $handlerClass
  *
  * @return TaskInterface
  */
 protected function createTask($workload, CronExpression $cronExpression = null, $handlerClass = TestHandler::class)
 {
     $task = $this->taskRepository->create($handlerClass, $workload);
     if ($cronExpression) {
         $task->setInterval($cronExpression, new \DateTime(), new \DateTime('+1 year'));
     }
     $this->taskRepository->save($task);
     return $task;
 }
Exemplo n.º 3
0
 public function testAddTask()
 {
     $task = $this->prophesize(TaskInterface::class);
     $task->getInterval()->willReturn(null);
     $task->getFirstExecution()->willReturn(new \DateTime());
     $execution = $this->prophesize(TaskExecutionInterface::class);
     $this->eventDispatcher->dispatch(Events::TASK_CREATE, Argument::that(function (TaskEvent $event) use($task) {
         return $event->getTask() === $task->reveal();
     }))->shouldBeCalled();
     $this->eventDispatcher->dispatch(Events::TASK_EXECUTION_CREATE, Argument::that(function (TaskExecutionEvent $event) use($task, $execution) {
         return $event->getTask() === $task->reveal() && $event->getTaskExecution() === $execution->reveal();
     }))->shouldBeCalled();
     $this->taskRepository->save($task->reveal())->shouldBeCalled();
     $this->taskExecutionRepository->findByTask($task)->willReturn([]);
     $this->taskExecutionRepository->findPending($task)->willReturn(null);
     $this->taskExecutionRepository->create($task, Argument::type(\DateTime::class))->willReturn($execution);
     $this->taskExecutionRepository->save($execution->reveal())->shouldBeCalledTimes(1);
     $this->taskScheduler->addTask($task->reveal());
 }