You are here

function _acquia_purge_diagnostics_status in Acquia Purge 7

Status.

Parameters

string $t: Name of the t() function to call.

AcquiaPurgeService $service: The Acquia Purge service.

Return value

array Associative array with the following elements:

2 string references to '_acquia_purge_diagnostics_status'
acquia_purge_acquia_purge_diagnostics in ./acquia_purge.module
Implements hook_acquia_purge_diagnostics().
acquia_purge_requirements in ./acquia_purge.install
Implements hook_requirements().

File

./acquia_purge.diagnostics.inc, line 27
Diagnostic self-tests and reports that aim to prevent runtime misery.

Code

function _acquia_purge_diagnostics_status($t, $service) {
  $passivemode = _acquia_purge_variable('acquia_purge_passivemode');
  $errorlimit = _acquia_purge_variable('acquia_purge_errorlimit');
  $stats = $service
    ->stats();
  $test = array(
    'title' => $t('Status'),
    'value' => $passivemode ? $t('Idle (passive mode)') : t('Idle'),
    'severity' => ACQUIA_PURGE_SEVLEVEL_INFO,
  );

  // When the user did not set a static integer as error limit, we calculate
  // it dynamically with limit = factor^3, with 20 as lowest limit. The higher
  // the factor is, the more tolerant our limit is. Limits for factors 1-14:
  // 20, 20, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, 1728, 2197, 2744
  if (!is_int($errorlimit)) {
    $factor = $service
      ->capacity()
      ->httpRequestsFactor();
    $errorlimit = $factor <= 2 ? 20 : ceil(pow($factor, 3));
  }
  if ($stats['bad'] > $errorlimit) {
    $test['severity'] = ACQUIA_PURGE_SEVLEVEL_ERROR;
    $test['description'] = $t('Acquia Purge failed over @limit times (@bad), since the last time the' . ' queue was processed. To avoid crashing your site with endless queue' . ' processing, cache invalidation has been disabled. We recommend you to' . " ask your site maintainer to check Drupal's watchdog logs for errors," . ' before lifting the blockade with "drush ap-forget".', array(
      '@limit' => $errorlimit,
      '@bad' => $stats['bad'],
    ));
    return $test;
  }

  // Report status if the system is running.
  if ($stats['running']) {
    if (!function_exists('theme')) {
      require_once DRUPAL_ROOT . '/includes/theme.inc';
    }
    $test['description'] = theme('acquia_purge_status_bar_widget', $stats);
    if ($stats['locked']) {
      $test['value'] = $test['value_plain'] = $t('Processing');
    }
    else {
      $test['value'] = $test['value_plain'] = $t('Items queued');
    }
  }
  return $test;
}