You are here

JobSchedulerInterface.php in Job Scheduler 8.2

Same filename and directory in other branches
  1. 8.3 src/JobSchedulerInterface.php

File

src/JobSchedulerInterface.php
View source
<?php

namespace Drupal\job_scheduler;


/**
 * Provides an interface defining a job scheduler manager.
 */
interface JobSchedulerInterface {

  /**
   * Returns scheduler info.
   *
   * @param string $name
   *   Name of the schedule.
   *
   * @return array
   *   Information for the schedule.
   *
   * @see hook_cron_job_scheduler_info()
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function info($name);

  /**
   * Adds a job to the schedule, replace any existing job.
   *
   * A job is uniquely identified by $job = array(type, id).
   *
   * @code
   * 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);
   * }
   * @endcode
   *
   * @param array $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.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function set(array $job);

  /**
   * Removes a job from the schedule, replace any existing job.
   *
   * A job is uniquely identified by $job = array(type, id).
   *
   * @param array $job
   *   A job to reserve.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function remove(array $job);

  /**
   * Removes all jobs for a given type.
   *
   * @param string $name
   *   Name of the schedule.
   * @param string $type
   *   The job type to remove.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function removeAll($name, $type);

  /**
   * Dispatches a job.
   *
   * Executes a worker callback or if schedule declares a queue name, queues a
   * job for execution.
   *
   * @param 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.
   */
  public function dispatch(array $job);

  /**
   * Executes a job.
   *
   * @param 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.
   */
  public function execute(array $job);

  /**
   * Re-schedules a job if intended to run again.
   *
   * If cannot determine the next time, drop the job.
   *
   * @param array $job
   *   The job to reschedule.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function reschedule(array $job);

  /**
   * Checks whether a job exists in the queue and update its parameters if so.
   *
   * @param array $job
   *   The job to reschedule.
   *
   * @return bool
   *   Execution result.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function check(array $job);

  /**
   * Perform periodic jobs.
   *
   * @return array
   *   Result of perform periodic jobs.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function perform();

  /**
   * Rebuilds a single scheduler.
   *
   * @param string $name
   *   The name of the schedule.
   * @param array $info
   *   (optional) The job info array. Defaults to null.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function rebuild($name, array $info = NULL);

  /**
   * Rebuilds all schedulers.
   *
   * @throws \Exception
   *   Exceptions thrown by code called by this method are passed on.
   */
  public function rebuildAll();

}

Interfaces

Namesort descending Description
JobSchedulerInterface Provides an interface defining a job scheduler manager.