You are here

function elysia_cron_execute in Elysia Cron 7

Same name and namespace in other branches
  1. 5.2 elysia_cron.module \elysia_cron_execute()
  2. 5 elysia_cron.module \elysia_cron_execute()
  3. 6 elysia_cron.module \elysia_cron_execute()
2 calls to elysia_cron_execute()
elysia_cron_execute_page in ./elysia_cron.admin.inc
elysia_cron_run in ./elysia_cron.module

File

./elysia_cron.module, line 1063

Code

function elysia_cron_execute($job) {
  global $elysia_cron_settings;
  if (variable_get('elysia_cron_debug_messages', 0)) {
    _dco_watchdog('cron', 'Cron job %job started.', array(
      '%job' => $job,
    ), WATCHDOG_NOTICE);
  }
  $time = time();
  elysia_cron_set($job, false, array(
    'running' => $time,
    'last_run' => $time,
  ));
  try {
    if (!empty($elysia_cron_settings[$job]['file'])) {
      include_once (!empty($elysia_cron_settings[$job]['file path']) ? $elysia_cron_settings[$job]['file path'] : drupal_get_path('module', $elysia_cron_settings[$job]['module'])) . DIRECTORY_SEPARATOR . $elysia_cron_settings[$job]['file'];
    }
    if (!empty($elysia_cron_settings[$job]['expression'])) {
      eval($elysia_cron_settings[$job]['expression']);
    }
    elseif (!empty($elysia_cron_settings[$job]['callback']) && function_exists($elysia_cron_settings[$job]['callback'])) {
      call_user_func_array($elysia_cron_settings[$job]['callback'], $elysia_cron_settings[$job]['arguments']);
    }
    else {
      _dco_watchdog('cron', 'Execution of ' . $job . ' failed, can\'t find function!', array(), WATCHDOG_ERROR);
    }
  } catch (Exception $e) {
    _dco_watchdog('cron', 'Exception: ' . $e, array(), WATCHDOG_ERROR);
    $exception = true;

    //TODO Manage it
  }
  $stats = elysia_cron_get_job_stats($job);
  $time = time() - $time;
  elysia_cron_set_job_stats($job, -1, $time, $c = $stats['execution_count'] + 1, round(($stats['avg_execution_time'] * ($c - 1) + $time) / $c, 2), $time > $stats['max_execution_time'] ? $time : -1, array(
    'running' => 0,
  ));
  if (variable_get('elysia_cron_debug_messages', 0)) {
    _dco_watchdog('cron', 'Cron job %job ended.', array(
      '%job' => $job,
    ), WATCHDOG_NOTICE);
  }
}