You are here

function _acquia_purge_queue_stats in Acquia Purge 6

Same name and namespace in other branches
  1. 7 acquia_purge.deprecated.inc \_acquia_purge_queue_stats()

Queue manager: generate progress statistics on the purge queue.

@returns Associative array with the keys 'running', 'total', 'remaining', 'processed', 'percent' and 'purgehistory'.

Parameters

string $log_purged_url: This optional parameter allows purge processors to record URLs that got purged successfully during runtime context. This facility is not persistent trough requests and only intended for GUI elements and statistics.

7 calls to _acquia_purge_queue_stats()
acquia_purge_ajax_processor in ./acquia_purge.admin.inc
Menu callback; process a chunk of purge items via AJAX.
acquia_purge_purge_path in ./acquia_purge.module
Purge a certain Drupal path from Varnish.
acquia_purge_purge_paths in ./acquia_purge.module
Purge a several Drupal paths from Varnish.
drush_acquia_purge_ap_forget in ./acquia_purge.drush.inc
Forget all scheduled purges and empty the queue.
drush_acquia_purge_ap_process in ./acquia_purge.drush.inc
Purge all queued items from the command line.

... See full list

File

./acquia_purge.module, line 979
Acquia Purge, Top-notch Varnish purging on Acquia Cloud!

Code

function _acquia_purge_queue_stats($log_purged_url = FALSE) {

  // Initialize the $purgehistory runtime log and add a extra path if provided.
  static $purgehistory;
  if (is_null($purgehistory)) {
    $purgehistory = array();
  }
  if ($log_purged_url) {
    if (!in_array($log_purged_url, $purgehistory)) {
      $purgehistory[] = $log_purged_url;
    }
  }

  // Initialize array with default values, except for the total counter.
  $info = array(
    'total' => variable_get('acquia_purge_queue_counter', 0),
    'remaining' => 0,
    'processed' => 0,
    'percent' => 100,
    'running' => FALSE,
    'purgehistory' => $purgehistory,
  );

  // Cut statistics gathering when the queue counter equals 0: not running.
  if ($info['total'] === 0) {
    return $info;
  }

  // Once we are here there are jobs running, lets update that.
  $info['running'] = TRUE;

  // Add 'remaining' and 'processed' counters.
  $info['remaining'] = db_query("SELECT COUNT(*) FROM {ap_queue}");
  $info['remaining'] = (int) db_result($info['remaining']);
  $info['processed'] = $info['total'] - $info['remaining'];

  // Calculate the percentage of the job.
  $info['percent'] = $info['remaining'] / $info['total'] * 100;
  $info['percent'] = (int) (100 - floor($info['percent']));
  return $info;
}