Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function scheduleTasks()
 {
     $tasks = $this->taskRepository->findEndBeforeNow();
     foreach ($tasks as $task) {
         $this->scheduleTask($task);
     }
 }
Ejemplo n.º 2
0
 public function testScheduleTasks()
 {
     $tasks = [$this->createTask($expression1 = CronExpression::factory('@hourly')), $this->createTask($expression2 = CronExpression::factory('@yearly')), $this->createTask(null, $date = new \DateTime('+1 day'))];
     $this->taskRepository->findEndBeforeNow()->willReturn($tasks);
     // single task
     $this->taskExecutionRepository->findByTask($tasks[2])->willReturn([]);
     // already scheduled
     $this->taskExecutionRepository->findPending($tasks[0])->willReturn($this->prophesize(TaskExecutionInterface::class)->reveal());
     $this->taskExecutionRepository->findPending($tasks[1])->willReturn(null);
     $this->taskExecutionRepository->findPending($tasks[2])->willReturn(null);
     $execution1 = $this->prophesize(TaskExecutionInterface::class);
     $execution1->setStatus(TaskStatus::PLANNED)->shouldBeCalled();
     $this->taskExecutionRepository->create($tasks[1], $expression2->getNextRunDate())->willReturn($execution1->reveal());
     $this->taskExecutionRepository->save($execution1)->shouldBeCalled();
     $execution2 = $this->prophesize(TaskExecutionInterface::class);
     $execution2->setStatus(TaskStatus::PLANNED)->shouldBeCalled();
     $this->taskExecutionRepository->create($tasks[2], $date)->willReturn($execution2->reveal());
     $this->taskExecutionRepository->save($execution2)->shouldBeCalled();
     $this->eventDispatcher->dispatch(Events::TASK_EXECUTION_CREATE, Argument::that(function (TaskExecutionEvent $event) use($tasks, $execution1) {
         return $event->getTask() === $tasks[1] && $event->getTaskExecution() === $execution1->reveal();
     }))->shouldBeCalled();
     $this->eventDispatcher->dispatch(Events::TASK_EXECUTION_CREATE, Argument::that(function (TaskExecutionEvent $event) use($tasks, $execution2) {
         return $event->getTask() === $tasks[2] && $event->getTaskExecution() === $execution2->reveal();
     }))->shouldBeCalled();
     $this->taskScheduler->scheduleTasks();
 }
Ejemplo n.º 3
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;
 }