You are here

function hosting_get_queues in Hosting 5

Same name and namespace in other branches
  1. 6.2 hosting.queues.inc \hosting_get_queues()
  2. 7.4 hosting.queues.inc \hosting_get_queues()
  3. 7.3 hosting.queues.inc \hosting_get_queues()

Retrieve a list of queues that need to be dispatched

Generate a list of queues, and the frequency / amount of items that need to be processed for each of them.

9 calls to hosting_get_queues()
hosting_dispatch in ./hosting.queues.inc
Main queue processing command for hostmaster.
hosting_drush_command in ./hosting.drush.inc
hosting_queues in ./hosting.module
List queues or tasks in a queue if a key is provided
hosting_queues_configure in ./hosting.module
Page callback
hosting_queues_configure_submit in ./hosting.module

... See full list

File

./hosting.queues.inc, line 47

Code

function hosting_get_queues($refresh = false) {
  static $cache = null;
  if (is_null($cache) || $refresh) {
    $cache = array();
    $defaults = array(
      'type' => 'serial',
      'max_threads' => 6,
      'threshold' => '100',
      'min_threads' => 1,
      'timeout' => strtotime("10 minutes", 0),
      'frequency' => strtotime("5 minutes", 0),
      'items' => 5,
      'enabled' => TRUE,
      'singular' => t('item'),
      'plural' => t('items'),
    );
    $queues = module_invoke_all("hosting_queues");
    foreach ($queues as $key => $queue) {
      $queue = array_merge($defaults, $queue);

      // Configurable settings.
      $configured = array(
        'frequency' => variable_get('hosting_queue_' . $key . '_frequency', $queue['frequency']),
        'items' => variable_get('hosting_queue_' . $key . '_items', $queue['items']),
        'enabled' => variable_get('hosting_queue_' . $key . '_enabled', $queue['enabled']),
        'last_run' => variable_get('hosting_queue_' . $key . '_last_run', false),
        'running' => variable_get('hosting_queue_' . $key . '_running', false),
        'interval' => variable_get('hosting_queue_' . $key . '_interval', false),
      );
      $queue = array_merge($queue, $configured);
      if ($queue['type'] == 'batch') {
        $threads = $queue['total_items'] / $queue['threshold'];
        if ($threads <= $queue['min_threads']) {
          $threads = $queue['min_threads'];
        }
        elseif ($thread > $queue['max_threads']) {
          $threads = $queue['max_threads'];
        }
        $queue['calc_threads'] = $threads;
        $queue['calc_frequency'] = ceil($queue['frequency'] / $threads);
        $queue['calc_items'] = ceil($queue['total_items'] / $threads);
      }
      else {
        $queue['calc_frequency'] = $queue['frequency'];
        $queue['calc_items'] = $queue['items'];
      }
      $queue['last'] = variable_get('hosting_queue_' . $key . '_last_run', 0);
      $queue['running'] = variable_get('hosting_queue_' . $key . '_running', 0);
      $queues[$key] = $queue;
    }
    $cache = $queues;
  }
  return $cache;
}