You are here

function elysia_cron_run in Elysia Cron 6.2

Same name and namespace in other branches
  1. 5.2 elysia_cron.module \elysia_cron_run()
  2. 5 elysia_cron.module \elysia_cron_run()
  3. 6 elysia_cron.module \elysia_cron_run()
  4. 7.2 elysia_cron.module \elysia_cron_run()
  5. 7 elysia_cron.module \elysia_cron_run()

Public function to invoke a complete cron_run

Parameters

$manual_run Consider launched by a user command (don't check for key/ip, protect current user...):

$ignore_disable Run the channel (and all it's jobs) even if disabled:

$ignore_time Run channel (and all it's jobs) job even if not ready:

$ignore_running Run the channel (and all it's jobs) even if already running:

4 calls to elysia_cron_run()
cron.php in ./cron.php
drush_elysia_cron_run_wrapper in ./elysia_cron.drush.inc
A drush command callback.
elysia_cron_cron in ./elysia_cron.module
Hook cron is invoked only by standard drupal cron. It's used to replace drupal cron.
elysia_cron_run_form_submit in ./elysia_cron.admin.inc
1 string reference to 'elysia_cron_run'
cron.php in ./cron.php

File

./elysia_cron.module, line 1062

Code

function elysia_cron_run($manual_run = false, $ignore_disable = false, $ignore_time = false, $ignore_running = false) {

  // If DISABLED block the execution
  if (!$ignore_disable && variable_get('elysia_cron_disabled', false)) {
    elysia_cron_debug("Cron globally disabled, skipping run");
    return;
  }

  // Check for CRON_KEY or ALLOWED_HOSTS
  if (!$manual_run) {
    $cron_key = variable_get('cron_key', '');
    if ($cron_key && !user_access('administer elysia_cron') && (empty($_GET['cron_key']) || $_GET['cron_key'] != $cron_key)) {
      elysia_cron_debug("Cron key mismatch, skipping run");
      return;
    }
    $allowed_hosts = variable_get('elysia_cron_allowed_hosts', false);
    if ($allowed_hosts && !user_access('administer elysia_cron') && !in_array(ip_address(), explode(",", $allowed_hosts))) {
      elysia_cron_debug("Cron ip address mismatch, skipping run");
      return;
    }
  }
  elysia_cron_prepare_run($manual_run);
  _ec_variable_set('elysia_cron_last_run', time());
  _ec_variable_set('cron_last', time());
  if ($execute = elysia_cron_lock_env()) {
    elysia_cron_initialize();
    $available_channel = elysia_cron_run_available_channel($ignore_disable, $ignore_time, $ignore_running);
    if ($available_channel) {

      // There are jobs ready to be executed
      // elysia_cron_internal_execute_channel calls elysia_cron_unlock_env
      elysia_cron_internal_execute_channel($available_channel['name'], $available_channel['jobs'], $ignore_running);
    }
    else {

      // No jobs should be executed, i must unlock cron semaphore
      elysia_cron_unlock_env();
      elysia_cron_debug('No channels ready to be executed, skipping cron.');
    }
  }
  elysia_cron_unprepare_run($manual_run);
  return $execute;
}