You are here

function Notifications_Queue::process_control in Notifications 6.4

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

6 calls to Notifications_Queue::process_control()
Notifications_Queue::message_send in includes/notifications_queue.class.inc
Message sending, pass the message to Messaging back end
Notifications_Queue::process_cron in includes/notifications_queue.class.inc
Callback for Drupal cron
Notifications_Queue::process_prepare in includes/notifications_queue.class.inc
Prepare subscriptions queue
Notifications_Queue::process_queue in includes/notifications_queue.class.inc
Process subscriptions queue
Notifications_Queue::process_rows in includes/notifications_queue.class.inc
Process rows given query conditions

... See full list

File

includes/notifications_queue.class.inc, line 160

Class

Notifications_Queue
Queue management and processing

Code

function process_control($op = 'check', $name = NULL, $value = NULL) {
  switch ($op) {
    case 'start':
      $this->process_current = array(
        'message' => 0,
        'step' => 0,
        'timer' => 0,
        'row' => 0,
      );
      $defaults = variable_get('notifications_process_limit', array(
        'time' => 0,
        'message' => 0,
        'row' => 0,
        'percent' => MESSAGING_DEFAULT_CRON_PERCENT,
      ));
      foreach ($defaults as $name => $value) {
        if ($value && !isset($this->process_limit[$name])) {
          $this->process_limit[$name] = $value;
        }
      }
      timer_start('notifications_process');
      break;
    case 'stop':
      $timer = timer_stop('notifications_process');
      $this->process_current['timer'] = $timer['time'];
      return $timer;
    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($this->process_limit['percent'])) {
          $timelimit[] = time() + $maxtime * $this->process_limit['percent'] / 100;
          unset($this->process_limit['percent']);
        }
      }

      // This is an absolute limit, applies always if set
      if (!empty($this->process_limit['time'])) {
        $timelimit[] = time() + $this->process_limit['time'];
      }
      if ($timelimit) {
        $this->process_limit['time'] = min($timelimit);
      }
      break;
    case 'init':
      $this->process_current[$name] = 0;
      $this->process_limit[$name] = $value;
      break;
    case 'current':

      // Return current value for counter
      return isset($this->process_current[$name]) ? $this->process_current[$name] : 0;
    case 'count':
      $value = $value ? $value : 1;
      isset($this->process_current[$name]) ? $this->process_current[$name] += $value : ($this->process_current[$name] = $value);
      break;
    case 'check':

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

      // Return array of variables needed to print out some messages
      return array(
        '@rows' => $this->process_current['row'],
        '@messages' => $this->process_current['message'],
        '@time' => $this->process_current['timer'],
      );
  }
}