You are here

function hosting_queued_restart in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 queued/hosting_queued.drush.inc \hosting_queued_restart()
  2. 7.3 queued/hosting_queued.drush.inc \hosting_queued_restart()

Restart the dispatcher to work around memory leaks

1 call to hosting_queued_restart()
drush_hosting_queued in queued/hosting_queued.drush.inc
Drush command to execute hosting tasks.
1 string reference to 'hosting_queued_restart'
drush_hosting_queued in queued/hosting_queued.drush.inc
Drush command to execute hosting tasks.

File

queued/hosting_queued.drush.inc, line 235
Dispatcher daemon

Code

function hosting_queued_restart($signal = NULL) {
  try {

    // If we received a singal, process it.
    if (!is_null($signal)) {
      watchdog('hosting_queued', 'Received signal @signal, waiting for children to die.', array(
        '@signal' => $signal,
      ));
      $status = NULL;
      pcntl_wait($status);
    }

    // We need the PCNTL extension to be able to auto restart.
    if (function_exists('pcntl_exec')) {
      $args = $_ENV['argv'];
      $drush = array_shift($args);

      // Strip sub-array to avoid warning "Array to string conversion"
      unset($_ENV['argv']);
      watchdog('hosting_queued', 'Restarting queue daemon with @drush @args.', array(
        '@drush' => $drush,
        '@args' => implode(" ", $args),
      ));
      drush_log('Releasing lock on task queue.');
      lock_release('hosting_queue_tasks_running');

      // close all open database file descriptors
      hosting_queued_db_close_all();
    }
    else {
      watchdog('hosting_queued', 'PCNTL not installed, unable to auto-restart.', array(), WATCHDOG_WARNING);
    }
  } catch (Exception $e) {

    // Caught ... dropping.
  }

  // New try block, to still restart if e.g. the watchog log ging faild on a missing DB connection.
  try {
    if (function_exists('pcntl_exec')) {
      pcntl_exec($drush, $args, $_ENV);
      drush_dog('Could not restart the queue daemon, aborting.', 'error');

      /* NOTREACHED */
    }
  } catch (Exception $e) {

    // Caught ... dropping.
  }
  drush_log('Releasing lock on task queue.');
  lock_release('hosting_queue_tasks_running');

  // Explicit exit in case we're handling a signal
  exit(1);
}