public function testPluginManagerThrowsExceptionOnInvalidJobClasses()
 {
     $jobPluginManager = new JobPluginManager();
     $jobPluginManager->setInvokableClass('InvalidJob', 'stdClass');
     $this->setExpectedException('SlmQueue\\Job\\Exception\\RuntimeException');
     $instance = $jobPluginManager->get('InvalidJob');
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // We do not need to check if jobs is an empty array because every the JobPluginManager automatically
     // adds invokables if the job name is not known, which will be sufficient most of the time
     $config = $serviceLocator->get('Config');
     $config = $config['slm_queue']['job_manager'];
     $jobPluginManager = new JobPluginManager(new Config($config));
     $jobPluginManager->setServiceLocator($serviceLocator);
     return $jobPluginManager;
 }
Beispiel #3
0
 /**
  * Push a job by its name onto the selected queue
  *
  * @param  string $name    Name of the job to create
  * @param  mixed $payload  Payload of the job set as content
  * @throws QueueNotFoundException If the method is called without a queue set
  * @return JobInterface    Created job by the job plugin manager
  */
 public function push($name, $payload = null)
 {
     if (null === $this->queue) {
         throw new QueueNotFoundException('You cannot push a job without a queue selected');
     }
     $job = $this->jobPluginManager->get($name);
     if (null !== $payload) {
         $job->setContent($payload);
     }
     return $this->queue->push($job);
 }
Beispiel #4
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());
 }
Beispiel #5
-2
 public function testMetadataIsPopped()
 {
     $this->sqsClient->expects($this->once())->method('receiveMessage')->will($this->returnValue(array('Messages' => array(array('Body' => json_encode(array('content' => serialize('aa'), 'metadata' => array('__name__' => 'MyClass', 'foo' => 'bar'))), 'MessageId' => 'id_123', 'ReceiptHandle' => 'receipt_123', 'MD5OfBody' => 'funny')))));
     $this->jobPluginManager->expects($this->once())->method('get')->with('MyClass')->will($this->returnValue(new Asset\SimpleJob()));
     $job = $this->sqsQueue->pop();
     $this->assertInstanceOf('SlmQueueSqsTest\\Asset\\SimpleJob', $job);
     $this->assertEquals('aa', $job->getContent());
     $this->assertEquals(array('__id__' => 'id_123', '__name__' => 'MyClass', 'receiptHandle' => 'receipt_123', 'md5' => 'funny', 'foo' => 'bar'), $job->getMetadata());
 }