/** * @test */ public function stoppWorkWhenMemoryExceeds() { $queueName = 'test' . uniqid(); $timeout = 3; $memoryLimit = 123; $this->extensionConfiguration->expects($this->any())->method('get')->with('memoryLimit')->will($this->returnValue($memoryLimit)); $job = new TestJob(); $this->jobManager->expects($this->once())->method('waitAndExecute')->with($queueName, $timeout)->will($this->returnValue($job)); $this->worker->expects($this->any())->method('memoryExceeded')->with($memoryLimit)->will($this->returnValue(true)); $this->worker->work($queueName, $timeout, Worker::LIMIT_QUEUE); }
/** * Prints information about a queue. * * @param string $queueName The name of the queue to work on * @cli */ public function infoCommand($queueName) { $queue = $this->jobManager->getQueueManager()->getQueue($queueName); $options = $queue->getOptions(); $this->outputFormatted('Information for queue "%s"...', [$queueName]); $this->outputFormatted('<b>Class:</b> %s', [get_class($queue)]); if (is_array($options) && !empty($options)) { foreach ($options as $key => $value) { $this->outputFormatted('<b>%s:</b> %s', [ucfirst($key), $value === null ? 'null' : $value]); } } }
/** * 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!'); }