Example #1
0
 /**
  * @inheritdoc
  */
 public function put(AbstractTube $tube, $data)
 {
     $workload = array('tube' => $tube->getName(), 'data' => $tube->getDataTransformer()->sleepData($data));
     $success = false;
     try {
         $success = $this->pheanstalk->put(json_encode($workload), $tube->getPriority(), $tube->getDelay(), $tube->getTtr());
     } catch (\Pheanstalk\Exception $e) {
         $this->fallBack($tube, $data);
     }
     return $success;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function put($data, $priority = PheanstalkInterface::DEFAULT_PRIORITY, $delay = PheanstalkInterface::DEFAULT_DELAY, $ttr = PheanstalkInterface::DEFAULT_TTR)
 {
     try {
         if (!is_string($data)) {
             $data = json_encode($data);
         }
         return $this->_beanstalk->put($data, $priority, $delay, $ttr);
     } catch (ConnectionException $e) {
         Yii::error($e);
         return false;
     }
 }
 /**
  * @inheritdoc
  */
 public function push($payload, $queue, $delay = PheanstalkInterface::DEFAULT_DELAY)
 {
     $priority = PheanstalkInterface::DEFAULT_PRIORITY;
     $ttr = PheanstalkInterface::DEFAULT_TTR;
     if (is_array($payload) && isset($payload['priority'])) {
         $priority = $payload['priority'];
         unset($payload['priority']);
     }
     if (is_array($payload) && isset($payload['ttr'])) {
         $ttr = $payload['ttr'];
         unset($payload['ttr']);
     }
     $payload = Json::encode(['id' => $id = md5(uniqid('', true)), 'body' => $payload]);
     $this->beanstalk->useTube($queue);
     $this->beanstalk->put($payload, $priority, $delay, $ttr);
     return $id;
 }
Example #4
0
 /**
  * @param Job $job
  * @param int $priority
  * @param int $delay (seconds)
  * @return Job
  */
 public static function queue(Job $job, $priority = Job::PRIORITY_NORMAL, $delay = 0)
 {
     if (OCTO_QUEUE_ENABLED) {
         $pheanstalk = new Pheanstalk(Config::getInstance()->get('Octo.worker.host'));
         $pheanstalk->useTube(OCTO_QUEUE);
         $id = $pheanstalk->put($job->toJson(), $priority, $delay);
         $job->setQueueId($id);
         $job = self::save($job);
     }
     return $job;
 }
<?php

/**
 * This file describes a Pheanstalk client.
 */
require_once dirname(__FILE__) . "/vendor/autoload.php";
use Pheanstalk\Pheanstalk;
// Create a new connection to pheanstalk.
$pheanstalk = new Pheanstalk('127.0.0.1');
// Use the test tube.
$pheanstalk->useTube('test');
// Grab command line arguments.
array_shift($argv);
$args = implode(' ', $argv);
// Send the command line args to pheanstalk.
for ($i = 0; $i < 1000; $i++) {
    $pheanstalk->put($args);
}
Example #6
0
 /**
  * Takes a build and puts it into the queue to be run (if using a queue)
  * @param Build $build
  */
 public function addBuildToQueue(Build $build)
 {
     $buildId = $build->getId();
     if (empty($buildId)) {
         return;
     }
     $config = Config::getInstance();
     $settings = $config->get('phpci.worker', []);
     if (!empty($settings['host']) && !empty($settings['queue'])) {
         $jobData = array('type' => 'phpci.build', 'build_id' => $build->getId());
         if ($config->get('using_custom_file')) {
             $jobData['config'] = $config->getArray();
         }
         $pheanstalk = new Pheanstalk($settings['host']);
         $pheanstalk->useTube($settings['queue']);
         $pheanstalk->put(json_encode($jobData), PheanstalkInterface::DEFAULT_PRIORITY, PheanstalkInterface::DEFAULT_DELAY, $config->get('phpci.worker.job_timeout', 600));
     }
 }