public function DailyTagPurgeLimitCheck::run in CloudFlare 8
Perform the check and determine the severity level.
Diagnostic checks determine whether something you are checking for is in shape, for instance CMI settings on which your plugin depends. Any check reporting self::SEVERITY_ERROR in their run() methods, will cause purge to stop working. Any other severity level will let the purgers proceed operating but you may report any warning through getRecommendation() to be shown on Drupal's status report, purge_ui or any other diagnostic listing.
public function run() {
if (...check..) {
return self::SEVERITY_OK;
}
return self::SEVERITY_WARNING;
}
@warning As diagnostic checks can be expensive, this method is called as rarely as possible. Checks derived from DiagnosticCheckBase will only see the check getting executed when any of the getter methods are called.
Return value
int Integer, matching either of the following constants:
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_INFO
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_OK
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_WARNING
- \Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface::SEVERITY_ERROR
Throws
\Drupal\purge\Plugin\Purge\DiagnosticCheck\Exception\CheckNotImplementedCorrectly Thrown when the return value is incorrect.
Overrides DiagnosticCheckInterface::run
File
- modules/
cloudflarepurger/ src/ Plugin/ Purge/ DiagnosticCheck/ DailyTagPurgeLimitCheck.php, line 80
Class
- DailyTagPurgeLimitCheck
- Checks that the site is within CloudFlare's daily tag purge rate limit.
Namespace
Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheckCode
public function run() {
if (!$this->areCloudFlareComposerDependenciesMet) {
$this->recommendation = $this
->t("Composer dependencies unmet. Unable to assess API rate limits.");
return SELF::SEVERITY_ERROR;
}
// Current number of purges today.
$daily_count = $this->state
->getTagDailyCount();
$this->value = $daily_count;
// Warn at 75% of capacity.
$daily_warning_level = 0.75 * CloudFlareAPI::API_TAG_PURGE_DAILY_RATE_LIMIT;
$message_variables = [
':daily_limit' => CloudFlareAPI::API_TAG_PURGE_DAILY_RATE_LIMIT,
':$daily_count' => $daily_count,
];
if ($daily_count >= CloudFlareAPI::API_TAG_PURGE_DAILY_RATE_LIMIT) {
$this->recommendation = $this
->t('Past Api limit of :daily_count/:daily_limit limit tag purges/day.', $message_variables);
return SELF::SEVERITY_ERROR;
}
elseif ($daily_count >= $daily_warning_level) {
$this->recommendation = $this
->t('Approaching Api limit of :daily_count/:daily_limit limit tag purges/day.', $message_variables);
return SELF::SEVERITY_WARNING;
}
elseif ($daily_count < $daily_warning_level) {
$this->recommendation = $this
->t('Site is safely below the daily limit of :daily_limit tag purges/day.', $message_variables);
return SELF::SEVERITY_OK;
}
}