public function testFailingJobThrowException()
 {
     /** @var SimpleQueue $queue */
     $queue = $this->queuePluginManager->get('knownQueue');
     $queue->push(new FailingJob());
     $routeMatch = new RouteMatch(['queue' => 'knownQueue']);
     $this->controller->getEvent()->setRouteMatch($routeMatch);
     $this->setExpectedException('SlmQueue\\Controller\\Exception\\WorkerProcessException');
     $this->controller->processAction();
 }
Esempio n. 2
0
 /**
  * Invoke plugin and optionally set queue
  *
  * @param  string $name Name of queue when set
  * @return self
  */
 public function __invoke($name = null)
 {
     if (null !== $name) {
         if (!$this->queuePluginManager->has($name)) {
             throw new QueueNotFoundException(sprintf("Queue '%s' does not exist", $name));
         }
         $this->queue = $this->queuePluginManager->get($name);
     }
     return $this;
 }
 /**
  * Process a queue
  *
  * @return string
  * @throws WorkerProcessException
  */
 public function processAction()
 {
     $options = $this->params()->fromRoute();
     $name = $options['queue'];
     $queue = $this->queuePluginManager->get($name);
     try {
         $messages = $this->worker->processQueue($queue, $options);
     } catch (ExceptionInterface $e) {
         throw new WorkerProcessException('Caught exception while processing queue', $e->getCode(), $e);
     }
     return $this->formatOutput($name, $messages);
 }
Esempio n. 4
0
 public function onSendEmail(Event $e)
 {
     /** @var QueueInterface $queue */
     $queue = $this->queues->get('user');
     $emailJob = $queue->getJobPluginManager()->get(SendEmailJob::class);
     $email = $e->getParams();
     $html = $this->renderer->render($email->getHtmlTemplate(), $email->getVars());
     $text = $this->renderer->render($email->getTextTemplate(), $email->getVars());
     $message = new MessageStruct();
     $message->html = $html;
     $message->text = $text;
     $message->to = $email->getTo();
     $emailJob->setContent($message);
     $queue->push($emailJob);
 }