You are here

function messaging_store_queue_process in Messaging 5

Same name and namespace in other branches
  1. 6 messaging.store.inc \messaging_store_queue_process()
  2. 6.2 messaging.store.inc \messaging_store_queue_process()
  3. 6.3 messaging.store.inc \messaging_store_queue_process()

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

File

./messaging.store.inc, line 21
Database storage for the messaging framework

Code

function messaging_store_queue_process() {
  $limit = variable_get('messaging_process_limit', array(
    'message' => 0,
    'time' => 0,
    'percent' => 0,
  ));

  // Calculate time limit. We get the smaller of all these times in seconds
  $timelimit[] = variable_get('cron_semaphore', 0) + ini_get('max_execution_time') - MESSAGING_TIME_MARGIN;
  if ($limit['time']) {
    $timelimit[] = time() + $limit['time'];
  }
  if ($limit['percent']) {
    $timelimit[] = time() + ini_get('max_execution_time') * $limit['percent'] / 100;
    unset($limit['percent']);
  }
  $limit['time'] = min($timelimit);

  // Processing loop. Will stop when we run out of rows or reach time limit
  do {
    $number = messaging_store_queue_process_step(MESSAGING_STEP_ROWS, $limit['time']);
  } while ($number == MESSAGING_STEP_ROWS && time() <= $limit['time']);
}