You are here

function messaging_store_queue_process_step in Messaging 5

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

Retrieve and send queued messages

Parameters

$limit: Maximum number of queued messages to process for this step

$timeout: Optional time limit for processing, will return when if reached during processing

Return value

Number of messages processed in this step

1 call to messaging_store_queue_process_step()
messaging_store_queue_process in ./messaging.store.inc
Process and send messages in queue, to be called from cron

File

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

Code

function messaging_store_queue_process_step($limit, $timeout = 0) {
  $count = 0;
  $sent = $unsent = array();
  $result = db_query_range("SELECT * FROM {messaging_store} WHERE queue = 1 AND cron = 1 ORDER BY mqid", 0, $limit);
  while ($message = db_fetch_array($result)) {
    messaging_store_unpack($message, TRUE);

    // Actual send function
    if (messaging_message_send_out($message['destination'], $message, $message['method'])) {
      $sent[] = $message['mqid'];
    }
    else {
      $unsent[] = $message['mqid'];
    }
    $count++;
    if ($timeout && time() > $timeout) {
      break;
    }
  }
  if ($sent) {
    messaging_store_sent($sent);
  }
  if ($unsent) {
    messaging_store_sent($unsent, TRUE);
  }
  return $count;
}