Exemple #1
0
 /**
  * @param string[] $names
  *
  * @return array
  */
 public function buildJobs($names)
 {
     foreach ($names as $name) {
         $jobInfo = $this->config['jobs'][$name];
         $description = isset($jobInfo['description']) ? $jobInfo['description'] : "";
         $job = new JobDefinition($name, $description);
         foreach ($jobInfo['tasks'] as $taskInfo) {
             $task = new TaskDefinition($taskInfo['type']);
             $task->setContinueOnError(isset($taskInfo['continueOnError']) ? $taskInfo['continueOnError'] : false);
             unset($taskInfo['type'], $taskInfo['continueOnError']);
             $task->setParameters($taskInfo);
             $job->addTask($task);
         }
         $this->registry->addJob($job);
     }
 }
Exemple #2
0
 /**
  * @param string[] $names
  *
  * @throws \Exception
  * @return array
  */
 private function buildJobs(array $names)
 {
     $jobs = $this->container->getParameter('jobs');
     foreach ($names as $name) {
         if (!array_key_exists($name, $jobs)) {
             throw new BldrException(sprintf("Job `%s` does not exist. Found: %s", $name, implode(', ', array_keys($jobs))));
         }
         $jobInfo = $jobs[$name];
         $description = isset($jobInfo['description']) ? $jobInfo['description'] : "";
         $job = new JobDefinition($name, $description);
         foreach ($jobInfo['tasks'] as $taskInfo) {
             $task = new TaskDefinition($taskInfo['type']);
             $task->setContinueOnError(isset($taskInfo['continueOnError']) ? $taskInfo['continueOnError'] : false);
             unset($taskInfo['type'], $taskInfo['continueOnError']);
             $task->setParameters($taskInfo);
             $job->addTask($task);
         }
         $this->registry->addJob($job);
     }
 }
Exemple #3
0
 /**
  * @param TaskInterface  $service
  * @param TaskDefinition $task
  *
  * @return TaskInterface
  */
 private function prepareServiceForTask(TaskInterface $service, TaskDefinition $task)
 {
     $this->dispatcher->dispatch(Event::PRE_INITIALIZE_TASK, new Event\PreInitializeTaskEvent($service));
     if ($service instanceof AbstractTask) {
         $service->configure();
     }
     if (method_exists($service, 'setEventDispatcher')) {
         $service->setEventDispatcher($this->dispatcher);
     }
     if (method_exists($service, 'setHelperSet')) {
         $service->setHelperSet($this->helperSet);
     }
     foreach ($task->getParameters() as $name => $value) {
         $service->setParameter($name, $value);
     }
     if (method_exists($service, 'validate')) {
         $service->validate();
     }
     return $service;
 }