You are here

JobCheckStatus.php in TMGMT Extension Suite 8

Same filename and directory in other branches
  1. 8.2 src/Plugin/QueueWorker/JobCheckStatus.php

File

src/Plugin/QueueWorker/JobCheckStatus.php
View source
<?php

namespace Drupal\tmgmt_extension_suit\Plugin\QueueWorker;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\tmgmt_extension_suit\ExtendedTranslatorPluginInterface;
use Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;

/**
 * Executes interface translation queue tasks.
 *
 * @QueueWorker(
 *   id = "tmgmt_extension_suit_check_status",
 *   title = @Translation("Job check status"),
 *   cron = {"time" = 30}
 * )
 */
class JobCheckStatus extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * @var \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem
   */
  protected $uniqueQueueItem;

  /**
   * @var LoggerInterface
   */
  protected $logger;

  /**
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * Constructs a new LocaleTranslation object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem $uniqueQueueItem
   * @param \Psr\Log\LoggerInterface $logger
   * @internal param \Drupal\Core\Queue\QueueInterface $queue The queue object.*   The queue object.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, UniqueQueueItem $uniqueQueueItem, LoggerInterface $logger) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->uniqueQueueItem = $uniqueQueueItem;
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('tmgmt_extension_suit.utils.queue_unique_item'), $container
      ->get('logger.channel.tmgmt_extension_suit'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $id = $data['id'];
    try {
      $job = entity_load('tmgmt_job', $id);
      if (!$job || !$job
        ->hasTranslator()) {
        return;
      }
      $plugin = $job
        ->getTranslator()
        ->getPlugin();
      if ($plugin instanceof ExtendedTranslatorPluginInterface && $plugin
        ->isReadyForDownload($job)) {
        $this->uniqueQueueItem
          ->addItem('tmgmt_extension_suit_download', $data);
      }
    } catch (\Exception $e) {
      $this->logger
        ->error($e
        ->getMessage());
    }
  }

}

Classes

Namesort descending Description
JobCheckStatus Executes interface translation queue tasks.