You are here

public function UltimateCronQueueSettings::cron_alter in Ultimate Cron 7.2

Implements hook_cron_alter().

Overrides UltimateCronPlugin::cron_alter

File

plugins/ultimate_cron/settings/queue.class.php, line 158
Queue settings for Ultimate Cron.

Class

UltimateCronQueueSettings
Queue settings plugin class.

Code

public function cron_alter(&$jobs) {
  if (!variable_get($this->key . '_enabled', TRUE)) {
    unset($jobs['ultimate_cron_plugin_settings_queue_cleanup']);
    return;
  }
  $new_jobs = array();
  foreach ($jobs as $job) {
    if (!$this
      ->isValid($job)) {
      continue;
    }
    $settings = $job
      ->getSettings();
    if (isset($settings['settings']['queue']['name'])) {
      if ($settings['settings']['queue']['throttle']) {
        for ($i = 2; $i <= $settings['settings']['queue']['threads']; $i++) {
          $name = $job->name . '_' . $i;
          $hook = $job->hook;
          $hook['settings']['queue']['master'] = $job->name;
          $hook['settings']['queue']['thread'] = $i;
          $hook['name'] = $name;
          $hook['title'] .= " (#{$i})";
          $hook['immutable'] = TRUE;
          $new_jobs[$name] = ultimate_cron_prepare_job($name, $hook);
          $new_jobs[$name]->settings = $settings + $new_jobs[$name]->settings;
          $new_jobs[$name]->title = $job->title . " (#{$i})";
        }
      }
    }
  }
  $jobs += $new_jobs;
  $jobs['ultimate_cron_plugin_settings_queue_cleanup']->settings += array(
    'scheduler' => array(),
  );
  $jobs['ultimate_cron_plugin_settings_queue_cleanup']->settings['scheduler'] += array(
    'crontab' => array(),
    'simple' => array(),
  );
  $jobs['ultimate_cron_plugin_settings_queue_cleanup']->settings['scheduler']['crontab'] += array(
    'rules' => array(
      '* * * * *',
    ),
  );
  $jobs['ultimate_cron_plugin_settings_queue_cleanup']->settings['scheduler']['simple'] += array(
    'rules' => array(
      '* * * * *',
    ),
  );
}