コード例 #1
0
 /**
  * Read message
  *
  * @param array $credentials
  * @throws \Sonar\Exceptions\BeanstalkMapperException
  * @return array
  */
 public function read(array $credentials)
 {
     try {
         while (($job = $this->connect->peekReady()) !== false) {
             $message = unserialize($job->getBody());
             if ($message['hash'] === $credentials['hash']) {
                 // hash found! Remove job from queue and return message
                 $job->delete();
                 unset($message['hash']);
                 return $message;
             }
         }
     } catch (\Exception $e) {
         throw new BeanstalkMapperException($e->getMessage());
     }
 }
コード例 #2
0
ファイル: Mailer.php プロジェクト: slowprog/phalcon-mailer
 /**
  * Handle queue piecemeal for periodic launch with cron 
  *
  * @param integer $limit
  */
 public function handleQueue($limit = 50)
 {
     while ((is_null($limit) || --$limit >= 0) && ($job = $this->queue->peekReady()) !== false) {
         $data = json_decode($job->getBody(), true);
         // 		    $segments = explode(':', $data['job']);
         // 		    if (count($segments) !== 2) continue;
         call_user_func_array([$this, 'sendSwiftMessage'], [unserialize($data['message'])]);
         $job->delete();
     }
 }
コード例 #3
0
ファイル: mailer.php プロジェクト: slowprog/phalcon-mailer
#!/usr/bin/env php
<?php 
use Phalcon\Queue\Beanstalk;
use Phalcon\Queue\Beanstalk\Job;
use Phalcon\DI;
use SlowProg\Mailer\MailerService;
// Подключаем конфиг приложения (исправить на свой)
$config = (require __DIR__ . '/app/config/config.php');
$di = new DI();
$di->set('config', $config);
$queue = new Beanstalk();
$queue->choose('mailer');
$di['queue'] = $queue;
/**
 * Register Mailer Service
 */
$di['mailer'] = function () {
    $service = new MailerService();
    return $service->mailer();
};
/** @var Job $job */
while (($job = $queue->peekReady()) !== false) {
    $data = json_decode($job->getBody(), true);
    $segments = explode(':', $data['job']);
    if (count($segments) !== 2) {
        continue;
    }
    call_user_func_array([$di[$segments[0]], $segments[1]], [$job, $data['data']]);
}
コード例 #4
0
ファイル: Beanstalk.php プロジェクト: mattvb91/cphalcon
 public function peekReady()
 {
     return parent::peekReady();
 }