public function JobScheduler::check in Job Scheduler 8.2
Same name and namespace in other branches
- 8.3 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 175
Class
- JobScheduler
- Manage scheduled jobs.
Namespace
Drupal\job_schedulerCode
public function check(array $job) {
$job += [
'id' => 0,
'period' => 0,
'crontab' => '',
];
$existing = $this->database
->select('job_schedule')
->fields('job_schedule')
->condition('name', $job['name'])
->condition('type', $job['type'])
->condition('id', $job['id'])
->execute()
->fetchAssoc();
// If existing, and changed period or crontab, reschedule the job.
if ($existing) {
if ($job['period'] != $existing['period'] || $job['crontab'] != $existing['crontab']) {
$existing['period'] = $job['period'];
$existing['crontab'] = $job['crontab'];
$this
->reschedule($existing);
}
return TRUE;
}
return FALSE;
}