You are here

function notifications_process in Notifications 6

Same name and namespace in other branches
  1. 5 notifications.cron.inc \notifications_process()
  2. 6.2 notifications.cron.inc \notifications_process()
  3. 6.3 notifications.cron.inc \notifications_process()

Controls and checks limits for queue processing It can be used by other modules to add their own limits here, like number of sms sent, etc...

Parameters

$op: 'start' => Start the counters 'cron' => Special time adjustment for cron operations 'init' => Start a new counter with $value limit 'option' => Sets /gets options

  • debug
  • output Enables output for admin page

Return value

TRUE if we are yet under the processing limits

5 calls to notifications_process()
notifications_admin_queue_process in ./notifications.admin.inc
Queue operations callback
notifications_message_send in ./notifications.cron.inc
Message sending
notifications_process_queue in ./notifications.cron.inc
Process subscriptions queue
notifications_process_run in ./notifications.cron.inc
Function to be called on cron by the main notifications_cron
notifications_process_send in ./notifications.cron.inc
Message delivery.

File

./notifications.cron.inc, line 96

Code

function notifications_process($op = 'check', $name = NULL, $value = NULL) {
  static $limit = array(), $options = array();
  static $current = array(
    'message' => 0,
    'step' => 0,
  );
  switch ($op) {
    case 'start':
      $defaults = variable_get('notifications_process_limit', array(
        'time' => 0,
        'message' => 0,
        'row' => 0,
        'percent' => 0,
      ));
      foreach ($defaults as $name => $value) {
        if ($value && !isset($limit[$name])) {
          $limit[$name] = $value;
        }
      }
      break;
    case 'cron':

      // Calculate time limit. We get the smaller of all these times in seconds
      // There's an issue with poormanscron not setting the cron semaphore so it will default to current time
      $timelimit = array();
      $cronstart = variable_get('cron_semaphore', time());

      // Max execution time may be zero meaning no limit, then no limits based on this
      if ($maxtime = ini_get('max_execution_time')) {
        $timelimit[] = $cronstart + $maxtime - NOTIFICATIONS_TIME_MARGIN;
        if (!empty($limit['percent'])) {
          $timelimit[] = time() + $maxtime * $limit['percent'] / 100;
          unset($limit['percent']);
        }
      }

      // This is an absolute limit, applies always if set
      if (!empty($limit['time'])) {
        $timelimit[] = time() + $limit['time'];
      }
      if ($timelimit) {
        $limit['time'] = min($timelimit);
      }
      break;
      break;
    case 'init':
      $current[$name] = 0;
      $limit[$name] = $value;
      break;
    case 'count':
      $value = $value ? $value : 1;
      isset($current[$name]) ? $current[$name] += $value : ($current[$name] = $value);
      break;
    case 'option':
      if (isset($value)) {
        $options[$name] = $value;
      }
      return isset($options[$name]) ? $options[$name] : FALSE;
  }
  $current['time'] = time();

  // Check all limits till we find a false one
  foreach ($limit as $name => $value) {
    if ($value && !empty($current[$name]) && $current[$name] >= $value) {
      watchdog('notifications', 'Reached processing limit on queue processing: %name = %value', array(
        '%name' => $name,
        '%value' => $value,
      ));
      return FALSE;
    }
  }
  return TRUE;
}