You are here

protected function CapacityTracker::gatherTimeHints in Purge 8.3

Gather ::getTimeHint() data by iterating all loaded purgers.

2 calls to CapacityTracker::gatherTimeHints()
CapacityTracker::getTimeHint in src/Plugin/Purge/Purger/CapacityTracker.php
Get the maximum number of seconds, a purger needs for one invalidation.
CapacityTracker::getTimeHintTotal in src/Plugin/Purge/Purger/CapacityTracker.php
Get the maximum number of seconds, processing a single invalidation takes.

File

src/Plugin/Purge/Purger/CapacityTracker.php, line 138

Class

CapacityTracker
Provides the capacity tracker.

Namespace

Drupal\purge\Plugin\Purge\Purger

Code

protected function gatherTimeHints() {
  if (is_null($this->timeHints)) {
    if (is_null($this->purgers)) {
      throw new \LogicException("::setPurgers() hasn't been called!");
    }
    $this->timeHints = [];
    if (count($this->purgers)) {
      foreach ($this->purgers as $id => $purger) {
        $hint = $purger
          ->getTimeHint();

        // Be strict about what values are accepted, better throwing
        // exceptions than having a crashing web application.
        if (!is_float($hint)) {
          $method = sprintf("%s::getTimeHint()", get_class($purger));
          throw new BadPluginBehaviorException("{$method} did not return a floating point value.");
        }
        if ($hint < 0.1) {
          $method = sprintf("%s::getTimeHint()", get_class($purger));
          throw new BadPluginBehaviorException("{$method} returned {$hint}, a value lower than 0.1.");
        }
        if ($hint > 10.0) {
          $method = sprintf("%s::getTimeHint()", get_class($purger));
          throw new BadPluginBehaviorException("{$method} returned {$hint}, a value higher than 10.0.");
        }
        $this->timeHints[$id] = $hint;
      }
    }
  }
}