function drush_acquia_purge_ap_process in Acquia Purge 7
Same name and namespace in other branches
- 6 acquia_purge.drush.inc \drush_acquia_purge_ap_process()
Purge all queued items from the command line.
1 call to drush_acquia_purge_ap_process()
- drush_acquia_purge_ap_purge in ./
acquia_purge.drush.inc - Purge a specified path from your balancers.
File
- ./
acquia_purge.drush.inc, line 281 - Drush integration providing common maintenance tasks.
Code
function drush_acquia_purge_ap_process(&$context = NULL) {
$service = _acquia_purge_service();
// Block processing in case of diagnostic problems.
if ($service
->diagnostics()
->isSystemBlocked()) {
drush_set_error(dt('Diagnostic error conditions were found, aborting.'));
return drush_acquia_purge_ap_diagnosis(ACQUIA_PURGE_SEVLEVEL_ERROR);
}
//
// MAIN DRUSH PROCESS.
//
if (is_null($context)) {
// Block at the main thread if there's locking active.
if ($service
->lockActive()) {
drush_set_error(dt('Locked, another process is running!'));
}
// Retrieve the statistics and determine if processing is needed.
$stats = $service
->stats();
if (!$stats['running']) {
return drush_print("The purge queue is empty, done!");
}
// Define the batch operation we're going to conduct.
$steps = (int) ceil($stats['remaining'] / $service
->capacity()
->queueClaimsLimit());
$batch = array(
'title' => dt('Purging'),
'operations' => array(),
'init_message' => t('Initializing'),
'error_message' => t('An error occurred'),
);
for ($i = 1; $i <= $steps; $i++) {
$batch['operations'][] = array(
__FUNCTION__,
array(),
);
}
// Store state data as it else won't be available to the sub processes.
$service
->state()
->commit();
// Kick off the batch process, which will start forking processes.
batch_set($batch);
$batch =& batch_get();
drush_backend_batch_process();
}
else {
if (!$service
->lockAcquire()) {
return drush_print("Unable to acquire lock, ensure that all users " . "close their browser tabs as a different purge seems to be active!");
}
// Process the maximum amount of paths we can process during runtime.
printf("\n# %d items left...\n", $service
->stats('remaining'));
if ($service
->process()) {
$printed_urls = array();
foreach ($service
->history() as $url) {
if (!in_array($url, $printed_urls)) {
drush_log(dt("Purged: @url", array(
'@url' => $url,
)), 'ok');
$printed_urls[] = $url;
}
}
}
// Inform the Batch API when the process is finished.
if (!$service
->stats('running')) {
$context['finished'] = 1;
$context['message'] = dt("Queue processed successfully!");
}
$service
->lockRelease();
}
}