You are here

function elysia_cron_internal_execute_job in Elysia Cron 7.2

Same name and namespace in other branches
  1. 6.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_run_job in ./elysia_cron.module
Public function to execute a single job.

File

./elysia_cron.module, line 1461

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'])) {
      $file_path = !empty($_elysia_cron_settings[$job]['file path']) ? $_elysia_cron_settings[$job]['file path'] : drupal_get_path('module', $_elysia_cron_settings[$job]['module']);
      $file_path .= DIRECTORY_SEPARATOR . $_elysia_cron_settings[$job]['file'];
      include_once $file_path;
    }
    if (!empty($_elysia_cron_settings[$job]['expression'])) {
      eval($_elysia_cron_settings[$job]['expression']);
    }
    elseif (!empty($_elysia_cron_settings[$job]['callback']) && is_callable($_elysia_cron_settings[$job]['callback'])) {
      call_user_func_array($_elysia_cron_settings[$job]['callback'], $_elysia_cron_settings[$job]['arguments']);
    }
    else {
      $function = $_elysia_cron_settings[$job]['module'] . '_cronapi';
      $arguments = array(
        'execute',
        $job,
      );
      if (is_callable($function)) {
        call_user_func_array($function, $arguments);
      }
      else {
        elysia_cron_error('Execution of ' . $job . ' failed, can\'t find function!', array(), TRUE);
      }
    }
  } catch (Exception $e) {
    watchdog_exception('cron', $e);
  }
  $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,
  ));
}