/** * {@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)); }
/** * Publishes a message to the backend. * * @param Message $message * @return void * @throws \RuntimeException If publishing fails */ public function produce(Message $message) { $type = $message->getType(); $body = array('ticket' => $message->getTicket()); try { $this->logger->debug(sprintf('Publish message for job %s to sonata backend', $message->getTicket()), ['type' => $type, 'body' => $body]); $queue = $this->registry->get($message->getType())->getQueue(); $this->backendProvider->getBackend($queue)->createAndPublish($type, $body); } catch (\Exception $e) { $this->logger->error(sprintf('Failed to publish message (Error: %s)', $e->getMessage()), ['exception' => $e]); if (!$e instanceof \RuntimeException) { $e = new \RuntimeException($e->getMessage(), $e->getCode(), $e); } throw $e; } }
/** * @param string $type The job type * @return array */ private function getParamTypes($type) { $jobType = $this->registry->get($type); $types = $jobType->getParameterTypes(); $indices = $jobType->getIndicesOfSerializableParameters(); $rs = array(); foreach ($indices as $index) { $rs[] = $types[$index]; } return $rs; }
/** * 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); }
/** * @expectedException \Abc\Bundle\JobBundle\Job\JobTypeNotFoundException */ public function testGetThrowsJobTypeNotFoundException() { $this->subject->get('foo'); }
/** * {@inheritdoc} */ public function produce(Message $message) { $producerMessage = new DefaultMessage('ConsumeJob', ['type' => $message->getType(), 'ticket' => $message->getTicket()]); $this->logger->debug('Publish message to bernard queue backend', ['message' => $message]); $this->producer->produce($producerMessage, $this->registry->get($message->getType())->getQueue()); }
/** * Deserializes the return of a job. * * @param string $type The job type * @param string $data * @return mixed */ public function deserializeReturnValue($type, $data) { $jobType = $this->registry->get($type); return $this->serializer->deserialize($data, $jobType->getReturnType(), 'json', $this->getResponseDeserializationContext($jobType)); }