/**
  * Process all pending tasks
  */
 public function work()
 {
     while (count($task = $this->_queue->receive()) > 0) {
         try {
             $taskData = $task->toArray();
             $this->getWorker()->execute($taskData[0]);
         } catch (Exception $e) {
             $this->_logger->logException($e);
         }
     }
 }
Beispiel #2
0
 /**
  * process number of messages in queue
  * 
  * @param integer $_numberOfMessagesToProcess
  */
 public function processQueue($_numberOfMessagesToProcess = 5)
 {
     if ($this->_queue && count($this->_queue) > 0) {
         $numberToProcess = min(array($_numberOfMessagesToProcess, count($this->_queue)));
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' processing messages: ' . $numberToProcess . ' of ' . count($this->_queue));
         $messages = $this->_queue->receive($numberToProcess);
         foreach ($messages as $i => $message) {
             $this->_executeAction($message->body);
             $this->_queue->deleteMessage($message);
         }
     }
 }
Beispiel #3
0
 /**
  * @group ZF-7650
  */
 public function testReceiveWillRetrieveZeroItems()
 {
     $options = $this->getTestConfig();
     $options['name'] = '/temp-queue/ZF7650';
     $queue = new Zend_Queue('Db', $options);
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
 }
Beispiel #4
0
 public function test_ZF_7650()
 {
     // Zend_Queue_Adapter_Array
     $queue = new Zend_Queue('Array');
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
     // Zend_Queue_Adapter_Memcacheq
     $driverOptions = array();
     if (defined('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST')) {
         $driverOptions['host'] = TESTS_ZEND_QUEUE_MEMCACHEQ_HOST;
     }
     if (defined('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT')) {
         $driverOptions['port'] = TESTS_ZEND_QUEUE_MEMCACHEQ_PORT;
     }
     $options = array('name' => 'ZF7650', 'driverOptions' => $driverOptions);
     $queue = new Zend_Queue('Memcacheq', $options);
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
     // Zend_Queue_Adapter_Db
     $driverOptions = array();
     if (defined('TESTS_ZEND_QUEUE_DB')) {
         require_once 'Zend/Json.php';
         $driverOptions = Zend_Json::decode(TESTS_ZEND_QUEUE_DB);
     }
     $options = array('name' => '/temp-queue/ZF7650', 'options' => array(Zend_Db_Select::FOR_UPDATE => true), 'driverOptions' => $driverOptions);
     $queue = new Zend_Queue('Db', $options);
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
     // Zend_Queue_Adapter_Activemq
     $driverOptions = array();
     if (defined('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST')) {
         $driverOptions['host'] = TESTS_ZEND_QUEUE_ACTIVEMQ_HOST;
     }
     if (defined('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT')) {
         $driverOptions['port'] = TESTS_ZEND_QUEUE_ACTIVEMQ_PORT;
     }
     if (defined('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME')) {
         $driverOptions['scheme'] = TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME;
     }
     $options = array('driverOptions' => $driverOptions);
     $queue = new Zend_Queue('Activemq', $options);
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
 }
Beispiel #5
0
 /**
  * @group ZF-7650
  */
 public function testReceiveWillRetrieveZeroItems()
 {
     $options = array('driverOptions' => $this->getTestConfig());
     $queue = new Zend_Queue('Activemq', $options);
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
 }
Beispiel #6
0
 /**
  * @group ZF-7650
  */
 public function testReceiveWillRetrieveZeroItems()
 {
     // Zend_Queue_Adapter_Array
     $queue = new Zend_Queue('Array');
     $queue2 = $queue->createQueue('queue');
     $queue->send('My Test Message 1');
     $queue->send('My Test Message 2');
     $messages = $queue->receive(0);
     $this->assertEquals(0, count($messages));
 }
Beispiel #7
0
require $root_directory . 'config.php';
require_once $root_directory . 'include/utils/utils.php';
require_once $root_directory . 'include/utils/CommonUtils.php';
require_once $root_directory . 'include/database/PearDatabase.php';
require_once $root_directory . 'include/logging.php';
require_once $root_directory . 'modules/Users/Users.php';
require_once $root_directory . 'include/utils/clean_incoming_data.php';
require_once $root_directory . 'user_privileges/seqprefix_config.php';
require_once $root_directory . 'include/Zend/Queue.php';
global $adb;
global $site_URL;
global $dbconfig;
$options = array('name' => 'queue1', 'driverOptions' => array('host' => $dbconfig['db_server'], 'port' => substr($dbconfig['db_port'], 1), 'username' => $dbconfig['db_username'], 'password' => $dbconfig['db_password'], 'dbname' => $dbconfig['db_name'], 'type' => 'pdo_mysql'));
$queue = new Zend_Queue('Db', $options);
//一分钟发送25条
$messages = $queue->receive(100);
foreach ($messages as $i => $message) {
    //参数字符串
    $postdata = $message->body;
    $posts = explode("&", $postdata);
    //sjid
    $sjid_arr = explode("=", $posts[0]);
    $sjid = $sjid_arr['1'];
    //maillogsid
    $maillogsid_arr = explode("=", $posts[1]);
    $maillogsid = $maillogsid_arr['1'];
    //判断是否已经发送过了
    $mailflag = checkMaillog($maillogsid);
    if (!$mailflag) {
        continue;
    }