예제 #1
3
 /**
  * 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 (ConnectionException $e) {
         \PHPUnit_Framework_Assert::fail("queue [{$queue}] not found");
     }
 }
 /**
  * @inheritdoc
  */
 public function purge($queue)
 {
     $stat = $this->beanstalk->statsTube($queue);
     $this->beanstalk->watch($queue);
     for ($i = 0; $i < $stat->current_jobs_ready; $i++) {
         $job = $this->beanstalk->peekReady();
         $this->beanstalk->delete($job);
     }
     for ($i = 0; $i < $stat->current_jobs_delayed; $i++) {
         $job = $this->beanstalk->peekDelayed();
         $this->beanstalk->delete($job);
     }
     for ($i = 0; $i < $stat->current_jobs_buried; $i++) {
         $job = $this->beanstalk->peekBuried();
         $this->beanstalk->delete($job);
     }
 }
 /**
  * @inheritdoc
  */
 public function count()
 {
     try {
         $clientStats = $this->client->statsTube($this->name);
         return (int) $clientStats['current-jobs-ready'];
     } catch (PheanstalkException $exception) {
         return 0;
     }
 }
예제 #4
0
 /**
  *
  * @return number
  */
 public function is_message($queue = '')
 {
     try {
         if ($queue) {
             $result = $this->beanstalk->statsTube($queue);
         } else {
             $result = $this->beanstalk->stats();
         }
         $messageCount = 0;
         foreach ($result as $key => $val) {
             if (in_array($key, ['current-jobs-urgent', 'current-jobs-ready', 'current-jobs-reserved', 'current-jobs-delayed'])) {
                 $messageCount += $val;
             }
         }
         return $messageCount;
     } catch (ServerException $e) {
         return 1;
     }
 }
예제 #5
0
파일: Stats.php 프로젝트: jimbojsb/bstools
 private function generateStatsTable(Pheanstalk $pheanstalk, $tube = null)
 {
     if ($tube) {
         $tubes[] = $tube;
     } else {
         $tubes = $pheanstalk->listTubes();
     }
     $stats = array();
     foreach ($tubes as $tube) {
         $stats[$tube] = (array) $pheanstalk->statsTube($tube);
     }
     $statsToDisplay = array('current-jobs-urgent', 'current-jobs-ready', 'current-jobs-reserved', 'current-jobs-delayed', 'current-jobs-buried', 'current-waiting', 'total-jobs');
     foreach ($stats as &$tubeStats) {
         foreach ($tubeStats as $key => $val) {
             if (!in_array($key, $statsToDisplay)) {
                 unset($tubeStats[$key]);
             }
         }
     }
     return $stats;
 }
예제 #6
0
 /** {@inheritdoc} */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $srcHost = $input->getArgument(self::ATTR_HOST);
     $srcPort = $input->getOption(self::OPT_PORT);
     $sort = $input->getOption(self::OPT_SORT);
     $order = $input->getOption(self::OPT_ORDER);
     $noZeros = $input->getOption(self::OPT_NO_ZEROS);
     $columns = ['name' => 'name', 'current-jobs-ready' => 'ready', 'current-jobs-reserved' => 'reserved', 'current-jobs-delayed' => 'delayed', 'current-jobs-buried' => 'buried'];
     $src = new Pheanstalk($srcHost, $srcPort);
     $table = new TableHelper(false);
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->setHeaders($columns);
     $tubeNames = $src->listTubes();
     ksort($tubeNames);
     $data = [];
     foreach ($tubeNames as $tube) {
         /** @var ArrayResponse $response */
         $response = $src->statsTube($tube);
         $tubeData = $response->getArrayCopy();
         $tubeData = array_intersect_key($tubeData, $columns);
         if ($noZeros) {
             foreach ($tubeData as $key => $value) {
                 if ('0' === $value) {
                     $tubeData[$key] = '';
                 }
             }
         }
         $data[] = $tubeData;
     }
     $column = array_search($sort, $columns);
     uasort($data, function (array $a1, array $a2) use($column, $order) {
         return strnatcmp($a1[$column], $a2[$column]) * $order;
     });
     $table->addRows($data);
     $table->render($output);
 }
 /**
  * Count messages in the queue
  *
  * @return integer
  */
 public function count()
 {
     $clientStats = $this->client->statsTube($this->name);
     return (int) $clientStats['current-jobs-ready'];
 }
예제 #8
0
 /**
  * @param $tube
  *
  * @return object|\Pheanstalk\Response
  */
 public function find($tube)
 {
     $info = $this->connection->statsTube($tube);
     return ['name' => $tube, 'jobs_total' => $info->total_jobs, 'jobs_ready' => $info->current_jobs_ready, 'jobs_reserved' => $info->current_jobs_reserved, 'jobs_urgent' => $info->current_jobs_urgent, 'jobs_delayed' => $info->current_jobs_delayed];
 }
예제 #9
0
 /**
  * Get the size of the queue.
  *
  * @param  string  $queue
  * @return int
  */
 public function size($queue = null)
 {
     $queue = $this->getQueue($queue);
     return (int) $this->pheanstalk->statsTube($queue)->total_jobs;
 }