You are here

public function JobScheduler::set in Job Scheduler 7

Same name and namespace in other branches
  1. 6 JobScheduler.inc \JobScheduler::set()
  2. 7.2 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);
}

Parameters

$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.

File

./JobScheduler.inc, line 84
JobScheduler class.

Class

JobScheduler
Manage scheduled jobs.

Code

public function set($job) {
  $job['name'] = $this->name;
  $job['last'] = REQUEST_TIME;
  $job['next'] = REQUEST_TIME + $job['period'];
  $job['scheduled'] = 0;
  $this
    ->remove($job);
  drupal_write_record('job_schedule', $job);
}