}
     }
 }
 # check provisioning jobs
 #
 $rs = $db->execute('SELECT `id`, `running`, `minute`, `hour`, `day`, `month`, `dow`, `data` ' . 'FROM `prov_jobs` ' . 'WHERE `phone_id`=' . $phone_id . ' AND `type`=\'firmware\' ' . 'ORDER BY `running` DESC, `inserted`');
 /*if (! $rs) {
 		gs_log( GS_LOG_WARNING, "DB error" );
 		return;
 	}*/
 while ($job = $rs->fetchRow()) {
     if ($job['running']) {
         break;
     }
     # check cron rule
     $c = new CronRule();
     $ok = $c->set_Rule($job['minute'] . ' ' . $job['hour'] . ' ' . $job['day'] . ' ' . $job['month'] . ' ' . $job['dow']);
     if (!$ok) {
         gs_log(GS_LOG_WARNING, "Phone {$mac}: Job " . $job['id'] . " has a bad cron rule (" . $c->errMsg . "). Deleting ...");
         $db->execute('DELETE FROM `prov_jobs` WHERE `id`=' . (int) $job['id'] . ' AND `running`=0');
         unset($c);
         continue;
     }
     if (!$c->validate_time()) {
         gs_log(GS_LOG_DEBUG, "Phone {$mac}: Job " . $job['id'] . ": Rule does not match");
         unset($c);
         continue;
     }
     unset($c);
     gs_log(GS_LOG_DEBUG, "Phone {$mac}: Job " . $job['id'] . ": Rule match");
     $fw_new_vers = _grandstream_normalize_version($job['data']);
Ejemplo n.º 2
0
 /**
  * Determine if job is behind schedule.
  */
 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;
 }
Ejemplo n.º 3
0
 /**
  * Get next schedule time of rule in UNIX timestamp format.
  *
  * @return int
  *   UNIX timestamp of next schedule time.
  */
 public function getNextSchedule()
 {
     $time = $this->time;
     $last_schedule = $this->getLastSchedule();
     $next_schedule = NULL;
     // Do a binary search for the next schedule.
     $interval = 86400 * 30;
     $offset = $interval;
     do {
         $test = new CronRule($this->rule, $time + (int) $offset, $this->skew);
         $schedule = $test->getLastSchedule();
         $interval /= 2;
         if ($schedule > $last_schedule) {
             $next_schedule = $schedule;
             $offset -= $interval;
         } elseif ($next_schedule) {
             $offset += $interval;
         } else {
             // Increase interval by doubling up.
             // (we've already halved it, so now we quadrouple it).
             $offset = $interval *= 4;
         }
     } while ($interval > 30);
     return $next_schedule;
 }