You are here

public static function Messaging_Store::queue_process in Messaging 6.4

Process and send messages in queue, to be called from cron

It will check for predefined limits and repeat the cycle [fetch] -> [send] -> [check] until the queue is empty or any of the limits are met

The limits array may contain any of these conditions:

  • time, absolute max execution time
  • timeout, calculated time out (like for cron, based on the time we've been already running)
  • message, max number of messages sent
  • percent, max % of page execution time that can be spent on cron processing

Parameters

$limits: Optional limits for queue processing

Return value

Array of results indexed by message id

1 call to Messaging_Store::queue_process()
Messaging_Store::cron_process in includes/messaging_store.class.inc
Process messages on cron

File

includes/messaging_store.class.inc, line 61
Database storage for the messaging framework

Class

Messaging_Store
Default storage and queueing system for Messaging

Code

public static function queue_process($limits = array()) {
  $results = array();
  $limit = self::process_limits($limits);

  // Processing loop. Will stop when we run out of rows or reach time / messages limit
  $count = 0;
  $max = !empty($limit['message']) ? $limit['message'] : 0;
  do {
    $step = $max ? min(self::STEP_ROWS, $max - $count) : self::STEP_ROWS;
    $result = self::queue_process_step($step, $limit['timeout']);
    $number = count($result);
    $count += $number;
    $results = array_merge($results, $result);
  } while ($number == $step && (!$limit['timeout'] || time() <= $limit['timeout']) && (!$max || $max > $count));
  return $results;
}