You are here

public function JobScheduler::reschedule in Job Scheduler 8.2

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

Re-schedules a job if intended to run again.

If cannot determine the next time, drop the job.

Parameters

array $job: The job to reschedule.

Throws

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

Overrides JobSchedulerInterface::reschedule

2 calls to JobScheduler::reschedule()
JobScheduler::check in src/JobScheduler.php
Checks whether a job exists in the queue and update its parameters if so.
JobScheduler::execute in src/JobScheduler.php
Executes a job.

File

src/JobScheduler.php, line 149

Class

JobScheduler
Manage scheduled jobs.

Namespace

Drupal\job_scheduler

Code

public function reschedule(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;
  $job['scheduled'] = 0;
  if (!empty($job['crontab'])) {
    $crontab = $this->crontabDecorator
      ->decorate($job['crontab']);
    $job['next'] = $crontab
      ->nextTime($timestamp);
  }
  else {
    $job['next'] = $timestamp + $job['period'];
  }
  if ($job['next']) {
    $this
      ->doUpdate($job, [
      'item_id',
    ]);
  }
  else {

    // If no next time, it may mean it wont run again the next year (crontab).
    $this
      ->remove($job);
  }
}