public function testPluginValidation()
 {
     $manager = new QueuePluginManager();
     $queue = new \stdClass();
     $this->setExpectedException('SlmQueue\\Queue\\Exception\\RuntimeException');
     $manager->validatePlugin($queue);
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $config = $config['slm_queue']['queue_manager'];
     $queuePluginManager = new QueuePluginManager(new Config($config));
     $queuePluginManager->setServiceLocator($serviceLocator);
     return $queuePluginManager;
 }
 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. 4
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. 6
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);
 }
Esempio n. 7
0
 public function testPayloadCanBeInjectedViaPlugin()
 {
     $queuePluginManager = new QueuePluginManager();
     $jobPluginManager = new JobPluginManager();
     $name = 'DefaultQueue';
     $queue = $this->getMock('SlmQueueTest\\Asset\\SimpleQueue', ['push'], [$name, $jobPluginManager]);
     $job = new SimpleJob();
     $queue->expects($this->once())->method('push')->with($job)->will($this->returnValue($job));
     $queuePluginManager->setService($name, $queue);
     $jobPluginManager->setService('SimpleJob', $job);
     $plugin = new QueuePlugin($queuePluginManager, $jobPluginManager);
     $plugin->__invoke($name);
     $payload = ['foo' => 'bar'];
     $result = $plugin->push('SimpleJob', $payload);
     $this->assertSame($payload, $result->getContent());
 }