QueueLengthCheck.php in Akamai 8.3
File
src/Plugin/Purge/DiagnosticCheck/QueueLengthCheck.php
View source
<?php
namespace Drupal\akamai\Plugin\Purge\DiagnosticCheck;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\akamai\AkamaiClientInterface;
use GuzzleHttp\Exception\ClientException;
class QueueLengthCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $config;
protected $akamaiClient;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, AkamaiClientInterface $akamai_client) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->config = $config
->get('akamai.settings');
$this->akamaiClient = $akamai_client;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), \Drupal::service('akamai.client.factory')
->get());
}
public function run() {
if (!$this->akamaiClient
->usesQueue()) {
$this->recommendation = $this
->t("CCUv3 doesn't support queuing.");
return self::SEVERITY_OK;
}
try {
$length = $this->akamaiClient
->getQueueLength();
$this->recommendation = $length === 0 ? $this
->t('Purging queue is empty.') : $this
->formatPlural($length, '%count item in the queue', '%count items in the queue', [
'%count' => $length,
]);
return self::SEVERITY_OK;
} catch (ClientException $e) {
$this->recommendation = $this
->t('Unable to connect to the Akamai API. Please check your credentials and endpoint.');
return self::SEVERITY_ERROR;
}
}
}