/** * Executes the next job. * * @param string $queueName * @param int $timeout * @return boolean true if there are still jobs todo */ protected function waitAndExecute($queueName, $timeout) { $continueWork = true; try { $job = $this->jobManager->waitAndExecute($queueName, $timeout); if ($job === null) { $continueWork = false; } else { $this->getLogger()->info(sprintf('Job "%s" (%s) done in process %s', $job->getLabel(), $job->getIdentifier(), getmypid())); } } catch (\Exception $exception) { $this->getLogger()->error($exception->getMessage()); } return $continueWork; }
/** * @test * @depends waitAndExecuteJobThrowsException */ public function waitAndExecuteJobAttempsThreeTimes() { $attemps = 3; $this->extensionConfiguration->expects($this->any())->method('get')->will($this->returnValue($attemps)); $job = $this->getMock(TestJob::class, array('execute'), array(), '', false); $job->expects($this->any())->method('execute')->will($this->returnValue(false)); $this->jobManager->initializeObject(); $this->jobManager->queue($this->queueName, $job); $this->failedJobRepository->expects($this->once())->method('add'); for ($i = 0; $i < $attemps + 99; ++$i) { try { $queuedJob = $this->jobManager->waitAndExecute($this->queueName); if ($queuedJob === null) { break; } } catch (JobQueueException $exception) { if ($i + 1 < $attemps) { $this->assertEquals(1, $this->testQueue->count(), 'Job is not republished to queue!'); } } } $this->assertEquals($attemps, $i, 'To many attemps!'); $this->assertEquals(0, $this->testQueue->count(), 'Queue not empty!'); }