You are here

public function UltimateCronCrontabScheduler::isBehind in Ultimate Cron 7.2

Determine if job is behind schedule.

Overrides UltimateCronScheduler::isBehind

File

plugins/ultimate_cron/scheduler/crontab.class.php, line 141
Crontab cron job scheduler for Ultimate Cron.

Class

UltimateCronCrontabScheduler
Crontab scheduler.

Code

public function isBehind($job) {

  // Disabled jobs are not behind!
  if (!empty($job->disabled)) {
    return FALSE;
  }
  $log_entry = isset($job->log_entry) ? $job->log_entry : $job
    ->loadLatestLogEntry();

  // If job hasn't run yet, then who are we to say it's behind its schedule?
  // Check the registered time, and use that if it's available.
  $job_last_ran = $log_entry->start_time;
  if (!$job_last_ran) {
    $registered = variable_get('ultimate_cron_hooks_registered', array());
    if (empty($registered[$job->name])) {
      return FALSE;
    }
    $job_last_ran = $registered[$job->name];
  }
  $settings = $job
    ->getSettings($this->type);
  $skew = $this
    ->getSkew($job);
  $next_schedule = NULL;
  foreach ($settings['rules'] as $rule) {
    $cron = CronRule::factory($rule, $job_last_ran, $skew);
    $time = $cron
      ->getNextSchedule();
    $next_schedule = is_null($next_schedule) || $time < $next_schedule ? $time : $next_schedule;
  }
  $behind = REQUEST_TIME - $next_schedule;
  return $behind > $settings['catch_up'] ? $behind : FALSE;
}