class AcquiaLiftQueue in Acquia Lift Connector 7
Class AcquiaLiftQueue
This class is used for queueing http requests to Acquia Lift. It prevents duplicate items from being added during a request, which can happen when there are multiple calls to the agent save or option set save or delete functions.
Hierarchy
- class \SystemQueue implements DrupalReliableQueueInterface
- class \AcquiaLiftQueue
Expanded class hierarchy of AcquiaLiftQueue
1 string reference to 'AcquiaLiftQueue'
- acquia_lift_enable in ./
acquia_lift.install - Implements hook_enable().
File
- includes/
acquia_lift.classes.inc, line 1859 - Provides an agent type for Acquia Lift
View source
class AcquiaLiftQueue extends SystemQueue {
public static $items = array();
public static $retries = array();
const MAX_RETRIES = 15;
/**
* Takes necessary steps when an item has failed permanently.
*
* @param $item
*/
public static function handleFailedItem($item) {
if (!isset($item->data['agent'])) {
return;
}
personalize_pause_if_running($item->data['agent']);
}
/**
* Overrides SystemQueue::createItem().
*
* Prevents duplicate requests from being queued up during the same
* page request.
*
* @param $data
* @return bool|void
*/
public function createItem($data) {
if (isset($data['hash'])) {
if (in_array($data['hash'], self::$items)) {
return;
}
else {
self::$items[] = $data['hash'];
unset($data['hash']);
}
}
parent::createItem($data);
}
/**
* Overrides SystemQueue::releaseItem().
*
* Imposes a maximum number of retries for released items.
*
* @param $data
* @return bool|void
*/
public function releaseItem($item) {
if (!isset(self::$retries[$item->item_id])) {
self::$retries[$item->item_id] = 0;
}
elseif (self::$retries[$item->item_id] >= self::MAX_RETRIES) {
self::handleFailedItem($item);
$this
->deleteItem($item);
return;
}
parent::releaseItem($item);
self::$retries[$item->item_id]++;
}
/**
* Overrides SystemQueue::deleteQueue().
*/
public function deleteQueue() {
parent::deleteQueue();
self::$items = array();
}
}