예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function create(JobInterface $job)
 {
     $level = $this->registry->get($job->getType())->getLogLevel();
     if (false === $level) {
         return new NullLogger();
     } elseif (null === $level) {
         $level = $this->level;
     }
     $handlers = $this->handlerFactory->createHandlers($job, $level, $this->bubble);
     return new Logger($this->buildChannel($job), array_merge($handlers, $this->handlers));
 }
예제 #2
0
 /**
  * Copies properties of a job to another job
  *
  * @param JobInterface                             $from The job where properties are copied from
  * @param \Abc\Bundle\JobBundle\Model\JobInterface $to   The job where where properties are copied to
  * @return \Abc\Bundle\JobBundle\Model\JobInterface The copied job
  */
 public function copyJob(JobInterface $from, \Abc\Bundle\JobBundle\Model\JobInterface $to)
 {
     $to->setType($from->getType());
     $to->setResponse($from->getResponse());
     $to->setParameters($from->getParameters());
     if (null != $from->getStatus()) {
         $to->setStatus($from->getStatus());
     }
     foreach ($from->getSchedules() as $schedule) {
         $to->addSchedule($schedule);
     }
     return $to;
 }
예제 #3
0
 /**
  * Invokes the job.
  *
  * @param JobInterface     $job
  * @param ContextInterface $context
  * @return mixed
  * @throws JobTypeNotFoundException
  */
 public function invoke(JobInterface $job, ContextInterface $context)
 {
     $jobType = $this->registry->get($job->getType());
     $callableArray = $jobType->getCallable();
     $parameters = static::resolveParameters($jobType, $context, $job->getParameters());
     if (is_array($callableArray) && ($callable = $callableArray[0])) {
         if ($callable instanceof JobAwareInterface) {
             $callable->setJob($job);
         }
         if ($callable instanceof ManagerAwareInterface) {
             $callable->setManager($this->manager);
         }
         if ($callable instanceof ControllerAwareInterface) {
             $callable->setController($this->controllerFactory->create($job));
         }
         if ($callable instanceof LoggerAwareInterface && $context->has('abc.logger')) {
             $callable->setLogger($context->get('abc.logger'));
         }
     }
     return call_user_func_array($callableArray, $parameters);
 }
예제 #4
0
 /**
  * @param JobInterface $job
  * @throws \Exception
  */
 protected function publishJob(JobInterface $job)
 {
     $message = new Message($job->getType(), $job->getTicket());
     try {
         $this->producer->produce($message);
     } catch (\Exception $e) {
         $this->logger->critical(sprintf('Failed to publish message for job %s (Error: %s)', $job->getTicket(), $e->getMessage()), ['job' => $job, 'exception' => $e]);
         throw $e;
     }
 }