QueueSizeDiagnosticCheck.php in Purge 8.3
File
src/Plugin/Purge/DiagnosticCheck/QueueSizeDiagnosticCheck.php
View source
<?php
namespace Drupal\purge\Plugin\Purge\DiagnosticCheck;
use Drupal\purge\Plugin\Purge\Queue\StatsTrackerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class QueueSizeDiagnosticCheck extends DiagnosticCheckBase implements DiagnosticCheckInterface {
protected $purgeQueueStats;
public final function __construct(StatsTrackerInterface $purge_queue_stats, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->purgeQueueStats = $purge_queue_stats;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('purge.queue.stats'), $configuration, $plugin_id, $plugin_definition);
}
public function run() {
$this->value = $this->purgeQueueStats
->numberOfItems()
->getInteger();
if ($this->value === 0) {
$this->recommendation = $this
->t("Your queue is empty!");
return self::SEVERITY_OK;
}
elseif ($this->value < 30000) {
return self::SEVERITY_OK;
}
elseif ($this->value < 100000) {
$this->recommendation = $this
->t('Your queue holds more then 30 000 items, which is quite high. Although this may naturally occur in certain configurations there is a risk that a high volume causes your server to crash at some point. High volumes can happen when no processors are clearing your queue, or when queueing outpaces processing. Please have a closer look into nature of your queue volumes, to prevent Purge from shutting down cache invalidation when the threshold of 100 000 items is reached!');
return self::SEVERITY_WARNING;
}
else {
$this->recommendation = $this
->t('Your queue exceeded 100 000 items! This volume is extremely high and not sustainable at all, so Purge has shut down cache invalidation to prevent your servers from actually crashing. This can happen when no processors are clearing your queue, or when queueing outpaces processing. Please first solve the structural nature of the issue by adding processing power or reducing your queue loads. Empty the queue to unblock your system.');
return self::SEVERITY_ERROR;
}
}
}