You are here

function ultimate_cron_should_run in Ultimate Cron 8

Same name and namespace in other branches
  1. 6 ultimate_cron.module \ultimate_cron_should_run()
  2. 7 ultimate_cron.module \ultimate_cron_should_run()

Check if rule is scheduled to run at a given time.

Parameters

$rules: rules to validate.

$last_run: last time the rule was run.

$now: time of validation, set to NULL for now.

$catch_up: run if we missed our time window?

Return value

boolean TRUE if rule is scheduled to run, FALSE if not.

2 calls to ultimate_cron_should_run()
UltimateCronRulesUnitTestCase::runTest in tests/rules.test
ultimate_cron_hook_should_run in ./ultimate_cron.module
Check if a hook should be run now.

File

./ultimate_cron.module, line 1235
@todo Add filter on overview page. @todo Add log view (with graph). @todo Make proper markup for overview page. @todo Refactor drush stuff, too many intimate relations with Background Process @todo Refactor Cron % offset stuff. Too mixed up and…

Code

function ultimate_cron_should_run($rules, $last_run, $now = NULL, $catch_up = 0, $offset = 0) {
  $now = is_null($now) ? time() : $now;
  require_once 'CronRule.class.php';
  $cron = new CronRule();
  foreach ($rules as $rule) {
    $cron->rule = $rule;
    $cron->offset = $offset;
    $last_ran = $cron
      ->getLastRan($now);
    if ($last_ran > $last_run && $last_ran >= $now - $catch_up) {
      return TRUE;
    }
  }
  return FALSE;
}