You are here

class JobQueueWorker in Apigee Edge 8

Worker class for processing a queue item.

Plugin annotation


@QueueWorker(
  id = "apigee_edge_job",
  title = "Apigee Edge job runner",
)

Hierarchy

Expanded class hierarchy of JobQueueWorker

File

src/Plugin/QueueWorker/JobQueueWorker.php, line 37

Namespace

Drupal\apigee_edge\Plugin\QueueWorker
View source
class JobQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The job executor service.
   *
   * @var \Drupal\apigee_edge\JobExecutor
   */
  protected $executor;

  /**
   * The queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $queue;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, JobExecutorInterface $executor, QueueFactory $queue_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->executor = $executor;
    $this->queue = $queue_factory
      ->get('apigee_edge_job');
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {

    /** @var \Drupal\apigee_edge\JobExecutor $executor */
    $executor = $container
      ->get('apigee_edge.job_executor');

    /** @var \Drupal\Core\Queue\QueueFactory $queueFactory */
    $queue_factory = $container
      ->get('queue');
    return new static($configuration, $plugin_id, $plugin_definition, $executor, $queue_factory);
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $job = $this->executor
      ->select($data['tag']);
    if (!$job || $job
      ->getStatus() !== Job::SELECTED) {
      return;
    }
    $this->executor
      ->call($job);
    $this->queue
      ->createItem([
      'tag' => $data['tag'],
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JobQueueWorker::$executor protected property The job executor service.
JobQueueWorker::$queue protected property The queue object.
JobQueueWorker::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
JobQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
JobQueueWorker::__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.