You are here

trait JobCreatorTrait in Apigee Edge 8

A trait for all jobs that create other jobs.

Hierarchy

File

src/Job/JobCreatorTrait.php, line 27

Namespace

Drupal\apigee_edge\Job
View source
trait JobCreatorTrait {

  /**
   * Returns the job executor service.
   *
   * @return \Drupal\apigee_edge\JobExecutor
   *   The job executor service.
   */
  protected function getExecutor() : JobExecutor {
    return \Drupal::service('apigee_edge.job_executor');
  }

  /**
   * Schedules a job for execution.
   *
   * @param \Drupal\apigee_edge\Job\Job $job
   *   The job shluld be schedules.
   */
  protected function scheduleJob(Job $job) {
    $this
      ->getExecutor()
      ->save($job);
  }

  /**
   * Schedules multiple jobs for execution.
   *
   * @param \Drupal\apigee_edge\Job\Job[] $jobs
   *   The array of the jobs should be scheduled.
   */
  protected function scheduleJobs(array $jobs) {
    $executor = $this
      ->getExecutor();
    foreach ($jobs as $job) {
      $executor
        ->save($job);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JobCreatorTrait::getExecutor protected function Returns the job executor service.
JobCreatorTrait::scheduleJob protected function Schedules a job for execution.
JobCreatorTrait::scheduleJobs protected function Schedules multiple jobs for execution.