You are here

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

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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaLiftQueue::$items public static property
AcquiaLiftQueue::$retries public static property
AcquiaLiftQueue::createItem public function Overrides SystemQueue::createItem(). Overrides SystemQueue::createItem
AcquiaLiftQueue::deleteQueue public function Overrides SystemQueue::deleteQueue(). Overrides SystemQueue::deleteQueue
AcquiaLiftQueue::handleFailedItem public static function Takes necessary steps when an item has failed permanently.
AcquiaLiftQueue::MAX_RETRIES constant
AcquiaLiftQueue::releaseItem public function Overrides SystemQueue::releaseItem(). Overrides SystemQueue::releaseItem
SystemQueue::$name protected property The name of the queue this instance is working with.
SystemQueue::claimItem public function Claim an item in the queue for processing. Overrides DrupalQueueInterface::claimItem 1
SystemQueue::createQueue public function Create a queue. Overrides DrupalQueueInterface::createQueue
SystemQueue::deleteItem public function Delete a finished item from the queue. Overrides DrupalQueueInterface::deleteItem
SystemQueue::numberOfItems public function Retrieve the number of items in the queue. Overrides DrupalQueueInterface::numberOfItems
SystemQueue::__construct public function