예제 #1
0
 public function release(array $message, $delay = PheanstalkInterface::DEFAULT_DELAY)
 {
     $this->validateMessage($message);
     $this->beanstalkd->useTube($message['queue']);
     $job = new Job($message['id'], $message['body']);
     return $this->beanstalkd->release($job, PheanstalkInterface::DEFAULT_PRIORITY, $delay);
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function putInTube($tube, $data, $priority = PheanstalkInterface::DEFAULT_PRIORITY, $delay = PheanstalkInterface::DEFAULT_DELAY, $ttr = PheanstalkInterface::DEFAULT_TTR)
 {
     try {
         $this->_beanstalk->useTube($tube);
         return $this->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;
 }
예제 #4
0
파일: Manager.php 프로젝트: block8/octo
 /**
  * @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;
 }
예제 #5
0
 /**
  * @inheritdoc
  */
 public function enqueue($queue, $command)
 {
     return (bool) $this->beanstalk->useTube($queue)->put(serialize($command));
 }
예제 #6
0
 /**
  * Delete a message from the Beanstalk queue.
  *
  * @param string $queue        	
  * @param string $id        	
  * @return void
  */
 public function deleteMessage($queue, $id)
 {
     $this->pheanstalk->useTube($this->getQueue($queue))->delete($id);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     $this->client->useTube($this->name);
 }
예제 #8
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id, $index)
 {
     $datas = AdsAutoDetect::find($id);
     if (sizeof($datas) < 1) {
         return view('error', ['data' => 'nothing', 'msg' => 'invalid id: ' . (string) $id]);
     }
     // 如果当前全天节目已处理完毕,返回第二个
     if ($datas->status != 0) {
         return redirect('show/' . (string) ($id + 1) . '/1');
     }
     // 如果当前第index条目标广告已处理完毕,返回下一个
     $log = AdsAutoLog::where('s_id', '=', $id)->where('index_id', '=', $index)->get();
     while (sizeof($log) > 0) {
         $index++;
         $log = AdsAutoLog::where('s_id', '=', $id)->where('index_id', '=', $index)->get();
     }
     //$datas = AdsAutoDetect::find($id);
     $json = json_decode($datas->result);
     $total = sizeof($json);
     if ($index < $total) {
         $data = $json[$index];
         return view('detail', ['data' => $data, 'myid' => $id, 'total' => $total, 'current' => $index]);
     } else {
         if ($index == $total) {
             $datas->status = 1;
             $datas->save();
             $pheanstalk = new Pheanstalk('127.0.0.1');
             $pheanstalk->useTube('auto_ads')->put((string) $log->id);
             return redirect('/');
         } else {
             return view('error', ['data' => 'nothing', 'msg' => 'invalid index id: ' . (string) $index]);
         }
     }
 }
예제 #9
0
 /**
  * @param Message $message
  * @return void
  */
 public function queue(Message $message)
 {
     $data = json_encode(['recipient' => $message->getRecipient(), 'payload' => $message->getPayload()]);
     $this->pheanstalk->useTube($this->tube)->put($data);
 }
예제 #10
0
<?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);
}
예제 #11
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));
     }
 }
예제 #12
0
<?php

require 'vendor/autoload.php';
date_default_timezone_set('Europe/Riga');
$faker = Faker\Factory::create();
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk('beanstalkd');
$logger = new Monolog\Logger('worker');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
sleep(10);
while (true) {
    sleep(3);
    $originalData = ['text' => $faker->realText(60), 'status' => (int) $faker->boolean(), 'created_at' => date('Y-m-d H:i:s', time())];
    $data = json_encode($originalData);
    $logger->addInfo('Data to put', $originalData);
    $pheanstalk->useTube('todotube')->put($data);
    $logger->addInfo('Done!');
}
예제 #13
0
 /**
  * Push message
  *
  * @param array $data
  * @return int queue process id
  */
 public function push(array $data)
 {
     $pid = $this->broker->useTube(self::DEFAULT_TUBE)->put(json_encode($data));
     return $pid;
 }
예제 #14
0
 /**
  * {@inheritDoc}
  */
 public function kick($max)
 {
     $this->pheanstalk->useTube($this->getTubeName());
     return $this->pheanstalk->kick($max);
 }