public function JobScheduler::set in Job Scheduler 8.2
Same name and namespace in other branches
- 8.3 src/JobScheduler.php \Drupal\job_scheduler\JobScheduler::set()
Adds a job to the schedule, replace any existing job.
A job is uniquely identified by $job = array(type, id).
function worker_callback($job) {
// Work off job.
// Set next time to be called. If this portion of the code is not
// reached for some reason, the scheduler will keep periodically invoking
// the callback() with the period value initially specified.
$scheduler
->set($job);
}
Parameters
array $job: An array that must contain the following keys: 'type' - A string identifier of the type of job. 'id' - A numeric identifier of the job. 'period' - The time when the task should be executed. 'periodic' - True if the task should be repeated periodically.
Throws
\Exception Exceptions thrown by code called by this method are passed on.
Overrides JobSchedulerInterface::set
1 call to JobScheduler::set()
- JobScheduler::rebuild in src/
JobScheduler.php - Rebuilds a single scheduler.
File
- src/
JobScheduler.php, line 65
Class
- JobScheduler
- Manage scheduled jobs.
Namespace
Drupal\job_schedulerCode
public function set(array $job) {
$timestamp = $this->time
->getRequestTime();
$job['periodic'] = isset($job['periodic']) ? (int) $job['periodic'] : 0;
$job['data'] = isset($job['data']) ? serialize($job['data']) : FALSE;
$job['last'] = $timestamp;
if (!empty($job['crontab'])) {
$crontab = $this->crontabDecorator
->decorate($job['crontab']);
$job['next'] = $crontab
->nextTime($timestamp);
}
else {
$job['next'] = $timestamp + $job['period'];
}
$job['scheduled'] = 0;
$this
->remove($job);
$this->database
->insert('job_schedule')
->fields($job)
->execute();
}