Ejemplo n.º 1
0
 /**
  * Ensure that an existing (previously processed) job can be removed from the event
  */
 public function testEventJobCanBeCleared()
 {
     $event = new WorkerEvent($this->worker, $this->queue);
     $job = new SimpleJob();
     $event->setJob($job);
     $this->assertNotNull($event->getJob());
     $event->setJob(null);
     $this->assertNull($event->getJob());
 }
    public function setUp()
    {
        $jobPluginManager      = $this->getMock('SlmQueue\Job\JobPluginManager');
        $queue                 = $this->getMock(
            'SlmQueue\Queue\AbstractQueue',
            array(),
            array('queueName', $jobPluginManager)
        );
        $strategyPluginManager = $this->getMock('SlmQueue\Strategy\StrategyPluginManager');
        $eventManager          = $this->getMock('Zend\EventManager\EventManager');
        $worker                = $this->getMock('SlmQueue\Worker\AbstractWorker', array(), array($eventManager));
        $strategyMock          = $this->getMock('SlmQueue\Strategy\AbstractStrategy');

        $queue->expects($this->any())->method('getName')->will($this->returnValue('queueName'));
        $worker->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
        $strategyPluginManager->expects($this->any())->method('get')->will($this->returnValue($strategyMock));

        $event = new WorkerEvent($worker, $queue);
        $job   = new SimpleJob();

        $event->setJob($job);

        $this->listener = new AttachQueueListenersStrategy($strategyPluginManager, array('queueName' => array(
            'SlmQueue\Strategy\SomeStrategy',
        )));

        $this->event    = $event;
    }
 public function setUp()
 {
     $queue = $this->getMockBuilder('SlmQueue\\Queue\\AbstractQueue')->disableOriginalConstructor()->getMock();
     $worker = $this->getMock('SlmQueue\\Worker\\WorkerInterface');
     $ev = new WorkerEvent($worker, $queue);
     $job = new SimpleJob();
     $ev->setJob($job);
     $this->listener = new InterruptStrategy();
     $this->event = $ev;
 }
 public function setUp()
 {
     $queue = $this->getMockBuilder('SlmQueue\\Queue\\AbstractQueue')->disableOriginalConstructor()->getMock();
     $worker = new SimpleWorker();
     $event = new WorkerEvent($worker, $queue);
     $this->job = new SimpleJob();
     $event->setOptions(['foo' => 'bar']);
     $event->setJob($this->job);
     $this->listener = new ProcessQueueStrategy();
     $this->event = $event;
 }
 /**
  * @param  WorkerEvent $e
  * @return void
  */
 public function onJobPop(WorkerEvent $e)
 {
     $queue = $e->getQueue();
     $options = $e->getOptions();
     $job = $queue->pop($options);
     /** @var AbstractWorker $worker */
     $worker = $e->getTarget();
     $eventManager = $worker->getEventManager();
     $e->setJob($job);
     // The queue may return null, for instance if a timeout was set
     if (!$job instanceof JobInterface) {
         $eventManager->trigger(WorkerEvent::EVENT_PROCESS_IDLE, $e);
         // make sure the event doesn't propagate or it will still process
         $e->stopPropagation();
         return;
     }
     $eventManager->trigger(WorkerEvent::EVENT_PROCESS_JOB, $e);
 }