You are here

function hosting_run_queue in Hosting 7.3

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

Run a queue specified by hook_hosting_queues()

Run an instance of a queue processor. This function contains all the book keeping functionality needed to ensure that the queues are running as scheduled.

Related topics

1 string reference to 'hosting_run_queue'
hosting_drush_command in ./hosting.drush.inc
Implements hook_drush_command().

File

./hosting.queues.inc, line 143
This file defines an API for defining new queues.

Code

function hosting_run_queue() {
  $cmd = drush_get_command();
  $queue = $cmd['queue'];
  $count = drush_get_option(array(
    'i',
    'items',
  ), 5);

  // process a default of 5 items at a time.
  $semaphore = "hosting_queue_{$queue}_running";
  variable_set('hosting_queue_' . $queue . '_last_run', $t = REQUEST_TIME);
  drush_log(dt('Acquiring lock on @queue queue.', array(
    '@queue' => $queue,
  )));
  $lock_wait = drush_get_option('lock-wait', HOSTING_QUEUE_DEFAULT_LOCK_WAIT);
  if (!lock_wait($semaphore, $lock_wait) || drush_get_option('force', FALSE)) {
    if (lock_acquire($semaphore, HOSTING_QUEUE_LOCK_TIMEOUT)) {
      drush_log(dt('Acquired lock on @queue queue.', array(
        '@queue' => $queue,
      )));
    }
  }
  elseif (drush_get_option('force', FALSE)) {
    drush_log(dt('Bypassing lock on @queue queue.', array(
      '@queue' => $queue,
    )), 'warning');
  }
  else {
    drush_die(dt('Cannot acquire lock on @queue queue.', array(
      '@queue' => $queue,
    )));
  }
  $func = "hosting_" . $queue . "_queue";
  if (function_exists($func)) {
    $func($count);
  }
  drush_log(dt('Releasing @queue lock.', array(
    '@queue' => $queue,
  )));
  lock_release($semaphore);
}