You are here

function ultimate_cron_cron_run_compatibility in Ultimate Cron 7.2

Run cron in compatibility mode.

Runs all non core cron jobs first, then locks core cron jobs, and then assumes that the consumer of this function will execute the core cron jobs.

If a lock cannot be obtained for a core cron job, an exception will be thrown since it will then be unsafe to run it.

1 call to ultimate_cron_cron_run_compatibility()
ultimate_cron_cron_queue_info in ./ultimate_cron.module
Implements hook_cron_queue_info().

File

./ultimate_cron.module, line 1083

Code

function ultimate_cron_cron_run_compatibility() {

  // Normally core cron just runs all the jobs regardless of schedule
  // and locks.
  // By default we will also run all Ultimate Cron jobs regardless of
  // their schedule. This behavior can be overridden via the variable:
  // "ultimate_cron_check_schedule_on_core_cron".
  //
  // Split up jobs between core and non-core, and run the non-core jobs
  // first.
  foreach (_ultimate_cron_job_load_all() as $job) {
    if (in_array('core', $job->hook['tags'])) {
      $core_jobs[] = $job;
    }
    else {
      if (!variable_get('ultimate_cron_check_schedule_on_core_cron', FALSE) || $job
        ->isScheduled()) {
        if ($lock_id = $job
          ->lock()) {
          $log_entry = $job
            ->startLog($lock_id, 'Launched by Drupal core');
          $job
            ->run();
          $log_entry
            ->finish();
          $job
            ->unlock();
        }
      }
    }
  }

  // Before passing control back to core, make sure that we can get a
  // lock on the jobs. If we can't, we don't allow core to run any
  // jobs, since we can't inform core which jobs are safe to run.
  foreach ($core_jobs as $job) {
    $lock_id = $job
      ->lock();
    if (!$lock_id) {
      throw new Exception(t('Could not acquire lock for @name', array(
        '@name' => $job->name,
      )));
    }
    $job
      ->startLog($lock_id, 'Launched by Drupal core');
  }
}