public function JobScheduler::reschedule in Job Scheduler 8.3
Same name and namespace in other branches
- 8.2 src/JobScheduler.php \Drupal\job_scheduler\JobScheduler::reschedule()
Re-schedules a job if intended to run again.
If cannot determine the next time, drop the job.
Parameters
JobSchedule $job: The job to reschedule.
Throws
\Exception Exceptions thrown by code called by this method are passed on.
Overrides JobSchedulerInterface::reschedule
2 calls to JobScheduler::reschedule()
- JobScheduler::check in src/
JobScheduler.php - Checks whether a job exists in the queue and update its parameters if so.
- JobScheduler::execute in src/
JobScheduler.php - Executes a job.
File
- src/
JobScheduler.php, line 146
Class
- JobScheduler
- Manage scheduled jobs.
Namespace
Drupal\job_schedulerCode
public function reschedule(JobSchedule $job) {
$timestamp = time();
$job
->setScheduled(0);
$job
->setLast($timestamp);
$crontab = $job
->getCrontab();
if (!empty($crontab)) {
$crontab = $this->crontabDecorator
->decorate($crontab);
$next = $crontab
->nextTime($timestamp);
}
else {
$next = $timestamp + $job
->getPeriod();
}
if ($next) {
$job
->setNext($next);
$job
->save();
}
else {
// If no next time, it may mean it wont run again the next year (crontab).
$job
->delete();
}
}