/** * Count the current number of messages on the queue. * * @param $queue Queue Name * * @return int Count */ public function getMessagesCurrentCountOnQueue($queue) { try { return $this->queue->statsTube($queue)['current-jobs-ready']; } catch (\Pheanstalk_Exception_ServerException $e) { \PHPUnit_Framework_Assert::fail("queue [{$queue}] not found"); } }
/** * See if we can talk to beanstalkd * */ function CheckBeanstalkd() { global $settings; $ret = false; require_once './lib/beanstalkd/pheanstalk_init.php'; $pheanstalk = new Pheanstalk_Pheanstalk($settings['beanstalkd']); if ($pheanstalk->getConnection()->isServiceListening()) { $id = $pheanstalk->putInTube('wpt.installtest', "test"); $jobStats = $pheanstalk->statsJob($id); $tubeStats = $pheanstalk->statsTube('wpt.installtest'); $job = $pheanstalk->reserveFromTube('wpt.installtest', 0); if ($job !== false && $job->getData() == 'test') { $ret = true; } $pheanstalk->delete($job); } return $ret; }
function PendingTestCount($crawl) { global $beanstalkd; global $pheanstalk; $count = false; do { if (!isset($pheanstalk)) { $pheanstalk = new Pheanstalk_Pheanstalk($beanstalkd); } $tube = 'har.' . $crawl; try { $stats = $pheanstalk->statsTube($tube); $count = intval($stats['current-jobs-ready']) + intval($stats['current-jobs-reserved']); } catch (Exception $e) { if ($e->getMessage() == 'Server reported NOT_FOUND') { $count = 0; } else { echo "statsTube exception: " . $e->getCode() . " - " . $e->getMessage() . "\n"; unset($pheanstalk); sleep(1); $pheanstalk = new Pheanstalk_Pheanstalk($beanstalkd); } } if ($count === false) { sleep(1); } } while ($count === false); return $count; }