/**
  * 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());
     }
 }
Esempio n. 2
0
 /**
  * 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();
     }
 }
Esempio n. 3
0
#!/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']]);
}
Esempio n. 4
0
 public function peekReady()
 {
     return parent::peekReady();
 }