/** * @inheritdoc */ public function collect(Request $request, Response $response, \Exception $exception = null) { $defaultPheanstalk = $this->pheanstalkLocator->getDefaultPheanstalk(); // Collect the information foreach ($this->pheanstalkLocator->getPheanstalks() as $name => $pheanstalk) { // Get information about this connection $this->data['pheanstalks'][$name] = ['name' => $name, 'host' => $pheanstalk->getConnection()->getHost(), 'port' => $pheanstalk->getConnection()->getPort(), 'timeout' => $pheanstalk->getConnection()->getConnectTimeout(), 'default' => $defaultPheanstalk === $pheanstalk, 'stats' => [], 'listening' => $pheanstalk->getConnection()->isServiceListening()]; // If connection is not listening, there is a connection problem. // Skip next steps which require an established connection if (!$pheanstalk->getConnection()->isServiceListening()) { continue; } $pheanstalkStatistics = $pheanstalk->stats()->getArrayCopy(); // Get information about this connection $this->data['pheanstalks'][$name]['stats'] = $pheanstalkStatistics; // Increment the number of jobs $this->data['jobCount'] += $pheanstalkStatistics['current-jobs-ready']; // Get information about the tubes of this connection $tubes = $pheanstalk->listTubes(); foreach ($tubes as $tubeName) { // Fetch next ready job and next buried job for this tube $this->fetchJobs($pheanstalk, $tubeName); $this->data['tubes'][] = ['pheanstalk' => $name, 'name' => $tubeName, 'stats' => $pheanstalk->statsTube($tubeName)->getArrayCopy()]; } } }
public function testGetDefaultPheanstalk() { $pheanstalkA = $this->getMockForAbstractClass(PheanstalkInterface::class); $pheanstalkB = $this->getMockForAbstractClass(PheanstalkInterface::class); $pheanstalkLocator = new PheanstalkLocator(); $pheanstalkLocator->addPheanstalk('default', $pheanstalkA, true); $pheanstalkLocator->addPheanstalk('foo', $pheanstalkB); $this->assertEquals($pheanstalkA, $pheanstalkLocator->getPheanstalk()); $this->assertEquals($pheanstalkA, $pheanstalkLocator->getDefaultPheanstalk()); $this->assertEquals($pheanstalkA, $pheanstalkLocator->getPheanstalk('default')); $this->assertEquals($pheanstalkB, $pheanstalkLocator->getPheanstalk('foo')); $this->assertEquals(['default' => $pheanstalkA, 'foo' => $pheanstalkB], $pheanstalkLocator->getPheanstalks()); }