/**
  * Set up dependencies
  */
 public function setUp()
 {
     parent::setUp();
     $configurationManager = $this->objectManager->get('TYPO3\\Flow\\Configuration\\ConfigurationManager');
     $settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.Jobqueue.Beanstalkd');
     if (!isset($settings['testing']['enabled']) || $settings['testing']['enabled'] !== TRUE) {
         $this->markTestSkipped('beanstalkd is not configured (TYPO3.Jobqueue.Beanstalkd.testing.enabled != TRUE)');
     }
     $queueName = 'Test-queue';
     $this->queue = new BeanstalkdQueue($queueName, $settings['testing']);
     $clientOptions = $settings['testing']['client'];
     $host = isset($clientOptions['host']) ? $clientOptions['host'] : '127.0.0.1';
     $port = isset($clientOptions['port']) ? $clientOptions['port'] : '11300';
     $this->client = new Pheanstalk($host, $port);
     // flush queue:
     try {
         while (true) {
             $job = $this->client->peekDelayed($queueName);
             $this->client->delete($job);
         }
     } catch (\Exception $e) {
     }
     try {
         while (true) {
             $job = $this->client->peekBuried($queueName);
             $this->client->delete($job);
         }
     } catch (\Exception $e) {
     }
     try {
         while (true) {
             $job = $this->client->peekReady($queueName);
             $this->client->delete($job);
         }
     } catch (\Exception $e) {
     }
 }
 /**
  * @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);
     }
 }
 /**
  * Peek for messages
  * NOTE: The beanstalkd implementation only supports to peek the UPCOMING job, so this will throw an exception for
  * $limit != 1.
  *
  * @param integer $limit
  * @return array Messages or empty array if no messages were present
  * @throws JobqueueException
  */
 public function peek($limit = 1)
 {
     if ($limit !== 1) {
         throw new JobqueueException('The beanstalkd Jobqueue implementation currently only supports to peek one job at a time', 1352717703);
     }
     try {
         $pheanstalkJob = $this->client->peekReady($this->name);
     } catch (ServerException $exception) {
         return array();
     }
     if ($pheanstalkJob === NULL || $pheanstalkJob === FALSE) {
         return array();
     }
     $message = $this->decodeMessage($pheanstalkJob->getData());
     $message->setIdentifier($pheanstalkJob->getId());
     $message->setState(Message::STATE_PUBLISHED);
     return array($message);
 }
 /**
  * @inheritdoc
  */
 public function flush()
 {
     try {
         while (true) {
             $job = $this->client->peekDelayed($this->name);
             $this->client->delete($job);
         }
     } catch (\Exception $e) {
     }
     try {
         while (true) {
             $job = $this->client->peekBuried($this->name);
             $this->client->delete($job);
         }
     } catch (\Exception $e) {
     }
     try {
         while (true) {
             $job = $this->client->peekReady($this->name);
             $this->client->delete($job);
         }
     } catch (\Exception $e) {
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $tube
  *
  * @return object|\Pheanstalk\Job
  */
 public function peek($tube)
 {
     $job = $this->connection->peekReady($tube);
     return ['id' => $job->getId(), 'raw' => $job->getData(), 'data' => json_decode($job->getData(), true), 'stats' => $this->findJob($job->getId())];
 }