public function testCreateTask() { $task = $this->prophesize(TaskInterface::class); $workload = 'Test 1'; $taskBuilder = $this->prophesize(TaskBuilderInterface::class); $this->taskRepository->create(TestHandler::class, $workload)->willReturn($task->reveal()); $this->factory->createTaskBuilder($task->reveal(), $this->taskScheduler)->willReturn($taskBuilder->reveal()); $result = $this->taskScheduler->createTask(TestHandler::class, $workload); $this->assertEquals($taskBuilder->reveal(), $result); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $handlerClass = $input->getArgument('handlerClass'); $workload = $input->getArgument('workload'); $cronExpression = $input->getOption('cron-expression'); $executionDateString = $input->getOption('execution-date'); $endDateString = $input->getOption('end-date'); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln(sprintf('Schedule task "%s" with workload "%s"', $handlerClass, $workload)); } $taskBuilder = $this->scheduler->createTask($handlerClass, $workload); if ($cronExpression !== null) { $endDate = null; if ($endDateString !== null) { $endDate = new \DateTime($endDateString); } $taskBuilder->cron($cronExpression, new \DateTime(), $endDate); } if ($executionDateString !== null) { $taskBuilder->executeAt(new \DateTime($executionDateString)); } $taskBuilder->schedule(); }