public function JobScheduler::check in Job Scheduler 8.3
Same name and namespace in other branches
- 8.2 src/JobScheduler.php \Drupal\job_scheduler\JobScheduler::check()
Checks whether a job exists in the queue and update its parameters if so.
Parameters
array $job: The job to reschedule.
Return value
bool Execution result.
Throws
\Exception Exceptions thrown by code called by this method are passed on.
Overrides JobSchedulerInterface::check
1 call to JobScheduler::check()
- JobScheduler::rebuild in src/
JobScheduler.php - Rebuilds a single scheduler.
File
- src/
JobScheduler.php, line 171
Class
- JobScheduler
- Manage scheduled jobs.
Namespace
Drupal\job_schedulerCode
public function check(array $job) {
$storage = $this->jobScheduleStorage;
$job += [
'id' => 0,
'period' => 0,
'crontab' => '',
];
$query = $storage
->getQuery();
$query
->condition('name', $job['name']);
$query
->condition('type', $job['type']);
$query
->condition('id', $job['id']);
$entity_ids = $query
->execute();
// If existing, and changed period or crontab, reschedule the job.
if ($entity_ids) {
/** @var JobSchedule $existing */
$existing = $storage
->load(reset($entity_ids));
if ($job['period'] != $existing
->getPeriod() || $job['crontab'] != $existing
->getCrontab()) {
$existing
->setPeriod($job['period']);
$existing
->setCrontab($job['crontab']);
$this
->reschedule($existing);
}
return TRUE;
}
return FALSE;
}