You are here

class JobSchedulerQueue in Job Scheduler 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/QueueWorker/JobSchedulerQueue.php \Drupal\job_scheduler\Plugin\QueueWorker\JobSchedulerQueue

Providing our own worker has the advantage that we can reschedule the job or take care of cleanup. Note that as we run the execute() action, the job won't be queued again this time.

Plugin annotation


@QueueWorker(
  id = "job_scheduler_queue",
  title = @Translation("Job Scheduler Queue"),
  cron = {"time" = 60},
  deriver = "Drupal\job_scheduler\Plugin\Derivative\JobSchedulerQueueWorker"
)

Hierarchy

Expanded class hierarchy of JobSchedulerQueue

File

src/Plugin/QueueWorker/JobSchedulerQueue.php, line 19

Namespace

Drupal\job_scheduler\Plugin\QueueWorker
View source
class JobSchedulerQueue extends QueueWorkerBase {

  /**
   * The name of this scheduler.
   *
   * @var \Drupal\job_scheduler\JobScheduler
   */
  protected $scheduler;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->scheduler = \Drupal::service('job_scheduler.manager');
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($job) {
    $scheduler = $this->scheduler;
    try {
      $scheduler
        ->execute($job);
    } catch (\Exception $e) {
      watchdog_exception('job_scheduler', $e);

      // Drop jobs that have caused exceptions.
      $scheduler
        ->remove($job);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JobSchedulerQueue::$scheduler protected property The name of this scheduler.
JobSchedulerQueue::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
JobSchedulerQueue::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.