You are here

dispatch.hosting.inc in Hosting 6.2

Same filename and directory in other branches
  1. 7.4 dispatch.hosting.inc
  2. 7.3 dispatch.hosting.inc

Drush include for the Hosting module's dispatch command.

File

dispatch.hosting.inc
View source
<?php

/**
 * @file
 *   Drush include for the Hosting module's dispatch command.
 */

/**
 * Main queue processing drush command for hostmaster.
 *
 * This is a single command, which will (based on configuration) run all the
 * other queue commands (cron, backup, tasks, stats). This is done so that there
 * is only one cron job to configure, and allow the frequency of calls to be
 * configured from the frontend interface.
 */
function drush_hosting_dispatch() {
  $now = time();
  variable_set("hosting_dispatch_last_run", $now);
  drush_log(t("dispatching queues"));
  $platform = node_load(HOSTING_OWN_PLATFORM);
  $root = $platform->publish_path;
  if (variable_get('hosting_dispatch_enabled', false)) {
    $queues = hosting_get_queues();
    foreach ($queues as $queue => $info) {

      // Check and release too old cron semaphore if exist
      $old_semaphore = variable_get('hosting_queue_' . $queue . '_running', false);
      if ($old_semaphore) {
        if (time() - $old_semaphore > 3600) {

          // Release too old cron semaphore
          variable_del('hosting_queue_' . $queue . '_running', false);
        }
      }
      if ($info['running']) {
        drush_log(dt("queue @queue already running", array(
          '@queue' => $queue,
        )));
      }
      else {
        if ($info['enabled']) {
          if ($now - $info["last"] >= $info["calc_frequency"] || drush_get_option('force', false)) {
            $count = $info['calc_items'] - $info['running_items'];
            if ($count <= 0) {
              drush_log(dt("maximum number of tasks (@count) already running", array(
                '@count' => $info['running_items'],
              )));
            }
            else {
              drush_log(dt("found @running running tasks, starting @count out of @max items", array(
                '@running' => $info['running_items'],
                '@count' => $count,
                '@max' => $info['calc_items'],
              )));
              drush_invoke_process('@self', "hosting-" . $queue, array(), array(
                'items' => $count,
                'strict' => FALSE,
              ), array(
                'fork' => TRUE,
              ));
            }
          }
          else {
            drush_log(dt("too early for queue @queue", array(
              '@queue' => $queue,
            )));
          }
        }
        else {
          drush_log(dt("queue @queue disabled", array(
            '@queue' => $queue,
          )));
        }
      }
    }
  }
  else {
    drush_log(dt("dispatching disabled"));
  }
}

Functions

Namesort descending Description
drush_hosting_dispatch Main queue processing drush command for hostmaster.