/** * 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 testOnJobPopPopsTriggersIdleAndStopPropagation() { $this->event->getQueue()->expects($this->once())->method('pop')->will($this->returnValue(null)); $called = false; $this->event->getTarget()->getEventManager()->attach(WorkerEvent::EVENT_PROCESS_IDLE, function (WorkerEvent $e) use(&$called) { $called = true; }); $this->listener->onJobPop($this->event); $this->assertTrue($called); $this->assertNull($this->event->getJob()); $this->assertEquals(WorkerEvent::JOB_STATUS_UNKNOWN, $this->event->getResult()); $this->assertTrue($this->event->propagationIsStopped()); }
/** * @param WorkerEvent $e */ public function onLogJobProcessStart(WorkerEvent $e) { $job = $e->getJob(); $name = $job->getMetadata('name'); if (null === $name) { $name = get_class($job); } $this->console->write(sprintf('Processing job %s...', $name)); }
/** * @param WorkerEvent $e * @return void */ public function onJobProcess(WorkerEvent $e) { $job = $e->getJob(); $queue = $e->getQueue(); /** @var AbstractWorker $worker */ $worker = $e->getTarget(); $result = $worker->processJob($job, $queue); $e->setResult($result); }