You are here

public function JobScheduler::execute in Job Scheduler 8.3

Same name and namespace in other branches
  1. 8.2 src/JobScheduler.php \Drupal\job_scheduler\JobScheduler::execute()

Executes a job.

Parameters

JobSchedule $job: A $job array as passed into set() or loaded.

Throws

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

Overrides JobSchedulerInterface::execute

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

File

src/JobScheduler.php, line 121

Class

JobScheduler
Manage scheduled jobs.

Namespace

Drupal\job_scheduler

Code

public function execute(JobSchedule $job) {
  $info = $this
    ->info($job
    ->getName());

  // If the job is periodic, re-schedule it before calling the worker.
  if ($job
    ->getPeriodic()) {
    $this
      ->reschedule($job);
  }
  else {
    $job
      ->delete();
  }
  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 {
    throw new JobSchedulerException(t('Could not find worker callback function: @function', [
      '@function' => $info['worker callback'],
    ]));
  }
}