You are here

function elysia_cron_internal_execute_job in Elysia Cron 6.2

Same name and namespace in other branches
  1. 7.2 elysia_cron.module \elysia_cron_internal_execute_job()

Internal function to execute a single job

2 calls to elysia_cron_internal_execute_job()
elysia_cron_internal_execute_channel in ./elysia_cron.module
Internal function to execute all jobs in a channel elysia_cron_lock_env() must be called BEFORE calling this method
elysia_cron_run_job in ./elysia_cron.module
Public function to execute a single job

File

./elysia_cron.module, line 1245

Code

function elysia_cron_internal_execute_job($job) {
  global $elysia_cron_settings;
  elysia_cron_debug('Cron job %job started.', array(
    '%job' => $job,
  ));
  $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 {
      elysia_cron_error('Execution of ' . $job . ' failed, can\'t find function!', array(), true);
    }
  } catch (Exception $e) {
    elysia_cron_error('Exception: ' . $e, array(), true);
    $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,
  ));
  elysia_cron_debug('Cron job %job ended in %time secs.', array(
    '%job' => $job,
    '%time' => $time,
  ));
}