You are here

public function JobScheduler::execute in Job Scheduler 7.2

Executes a job that.

@codingStandardsIgnoreStart

Parameters

array $job: A $job array as passed into set() or read from job_schedule table.

Throws

Exception Exceptions thrown by code called by this method are passed on.

1 call to JobScheduler::execute()
JobScheduler::dispatch in ./JobScheduler.inc
Dispatches a job.

File

./JobScheduler.inc, line 177
JobScheduler class.

Class

JobScheduler
Manage scheduled jobs.

Code

public function execute($job) {

  // @codingStandardsIgnoreEnd
  $info = $this
    ->info();

  // If the job is periodic, re-schedule it before calling the worker, just in
  // case.
  if ($job['periodic']) {
    $job['last'] = REQUEST_TIME;
    $this
      ->reschedule($job);
  }
  if (!empty($info['file']) && file_exists($info['file'])) {
    include_once $info['file'];
  }
  if (function_exists($info['worker callback'])) {
    call_user_func($info['worker callback'], $job);
  }
  else {

    // @todo If worker doesn't exist anymore we should do something about it, remove and throw exception?
    $this
      ->remove($job);
    throw new JobSchedulerException('Could not find worker callback function: ' . $info['worker callback']);
  }
}