headless_cms-1.0.3/modules/headless_cms_notify_webhook/src/Plugin/QueueWorker/HeadlessNotifyWebhookQueueWorker.php

modules/headless_cms_notify_webhook/src/Plugin/QueueWorker/HeadlessNotifyWebhookQueueWorker.php
<?php

declare(strict_types=1);

namespace Drupal\headless_cms_notify_webhook\Plugin\QueueWorker;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\Attribute\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\headless_cms_notify_webhook\HeadlessNotifyWebhookQueueItem;
use Drupal\headless_cms_notify_webhook\HeadlessNotifyWebhookService;
use Psr\Container\ContainerInterface;

/**
 * Dispatch cache webhooks.
 */
#[QueueWorker(
  id: 'headless_cms_notify_webhook',
  title: new TranslatableMarkup('Headless CMS Notify - Webhook Queue Worker'),
  cron: ['time' => 30],
)]
class HeadlessNotifyWebhookQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  const QUEUE_NAME = 'headless_cms_notify_webhook';

  /**
   * Construct new CacheWebhookQueueWorker.
   */
  public function __construct(
    protected EntityTypeManagerInterface $entityTypeManager,
    protected HeadlessNotifyWebhookService $webhookService,
    array $configuration,
    string $plugin_id,
    mixed $plugin_definition,
  ) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(
    ContainerInterface $container,
    array $configuration,
    $plugin_id,
    $plugin_definition,
  ): self {
    return new static(
      $container->get('entity_type.manager'),
      $container->get(HeadlessNotifyWebhookService::class),
      $configuration,
      $plugin_id,
      $plugin_definition
    );
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $item = HeadlessNotifyWebhookQueueItem::fromJson($data);

    $this->webhookService->send($item->url, $item->json, FALSE);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc