public function JobScheduler::set in Job Scheduler 7.2
Same name and namespace in other branches
- 6 JobScheduler.inc \JobScheduler::set()
- 7 JobScheduler.inc \JobScheduler::set()
Add 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);
}
@codingStandardsIgnoreStart
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. 'periodic' - True if the task should be repeated periodically.
The array must also contain one of the following keys: 'period' - The time when the task should be executed. 'crontab' - A crontab entry which describes the times a task should be executed.
File
- ./
JobScheduler.inc, line 86 - JobScheduler class.
Class
- JobScheduler
- Manage scheduled jobs.
Code
public function set($job) {
// @codingStandardsIgnoreEnd
$job['name'] = $this->name;
$job['last'] = REQUEST_TIME;
if (!empty($job['crontab'])) {
$crontab = new JobSchedulerCronTab($job['crontab']);
$job['next'] = $crontab
->nextTime(REQUEST_TIME);
}
else {
$job['next'] = REQUEST_TIME + $job['period'];
}
$job['scheduled'] = 0;
$this
->remove($job);
drupal_write_record('job_schedule', $job);
}