You are here

public static function Crontab::shouldRun in Ultimate Cron 8.2

1 call to Crontab::shouldRun()
RulesUnitTest::assertRule in tests/src/Unit/RulesUnitTest.php

File

src/Plugin/ultimate_cron/Scheduler/Crontab.php, line 138

Class

Crontab
Crontab scheduler.

Namespace

Drupal\ultimate_cron\Plugin\ultimate_cron\Scheduler

Code

public static function shouldRun($rules, $job_last_ran, $time = NULL, $catch_up = 0, $skew = 0) {
  $time = is_null($time) ? time() : $time;
  foreach ($rules as $rule) {
    $cron = CronRule::factory($rule, $time, $skew);
    $cron_last_ran = $cron
      ->getLastSchedule();

    // @todo: Right now second test is failing randomly on low $catch_up value.
    if ($job_last_ran < $cron_last_ran && $cron_last_ran <= $time) {
      if ($time <= $cron_last_ran + $catch_up || $catch_up == 0) {
        return $time - $job_last_ran;
      }
    }
  }
  return FALSE;
}