Пример #1
0
 /**
  * @param ControllerInterface $controller
  * @param JobManagerInterface $jobManager
  * @param JobInterface        $job
  * @throws \InvalidArgumentException If the given manager is not a manager of the given job
  */
 public function __construct(ControllerInterface $controller, JobManagerInterface $jobManager, JobInterface $job)
 {
     if (!$jobManager->isManagerOf($job)) {
         throw new \InvalidArgumentException('The job manager is not a manager of the job');
     }
     $this->controller = $controller;
     $this->jobManager = $jobManager;
     $this->job = $job;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function add(JobInterface $job)
 {
     if (null != $this->validator) {
         $this->logger->debug('Validate job');
         $errors = $this->validator->validate($job);
         if (count($errors) > 0) {
             $this->logger->debug('Validation failed with errors', ['errors' => $errors]);
             throw new ValidationFailedException($errors);
         }
     }
     if (!$this->jobManager->isManagerOf($job)) {
         $job = $this->helper->copyJob($job, $this->jobManager->create());
     }
     $job->setStatus(Status::REQUESTED());
     $job->setProcessingTime(0);
     $this->jobManager->save($job);
     $this->logger->info(sprintf('Added job %s of type "%s"', $job->getTicket(), $job->getType()), ['parameters' => $job->getParameters(), 'schedules' => $job->getSchedules()]);
     if (!$job->hasSchedules()) {
         $this->publishJob($job);
     }
     return $job;
 }