You are here

class AcquiaPurgeQueueSmart in Acquia Purge 7

Efficient query bundling database queue that disregards expired queue items.

This backend drops items from the queue that have been sitting there twice as long as the sites TTL is configured to. All load balancers that once had the item in cache, are assumed to have already refreshed the item long ago.

Hierarchy

Expanded class hierarchy of AcquiaPurgeQueueSmart

File

lib/queue/AcquiaPurgeQueueSmart.php, line 15
Contains SmartQueue.

View source
class AcquiaPurgeQueueSmart extends AcquiaPurgeQueueEfficient implements AcquiaPurgeQueueInterface {

  /**
   * Time in seconds Varnish is caching pages generated by Drupal.
   *
   * @var int
   */
  protected $ttl = 0;

  /**
   * Construct a AcquiaPurgeQueueSmart instance.
   *
   * @param AcquiaPurgeStateStorageInterface $state
   *   The state storage required for the queue counters.
   */
  public function __construct(AcquiaPurgeStateStorageInterface $state) {
    parent::__construct($state);
    $this->ttl = (int) variable_get('page_cache_maximum_age', 0);
  }

  /**
   * Expire queue items that should have already expired externally.
   */
  protected function expireQueueItems() {

    // Do not bother expiry under the following conditions.
    $expired = time() - 2 * $this->ttl;
    if ($this->ttl < 20) {
      return;
    }
    if ($expired < 1 || $expired >= time()) {
      return;
    }

    // Delete items from the queue that expired and need no processing by AP.
    $deleted_items = db_delete('queue')
      ->condition('name', $this->name)
      ->condition('created', $expired, '<')
      ->execute();
    if ($deleted_items > 0) {
      watchdog('acquia_purge', "Disregarded %n expired items from the queue (smart queue backend).", array(
        '%n' => $deleted_items,
      ), WATCHDOG_INFO);
      $this
        ->total()
        ->decrease($deleted_items);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function claimItem($lease_time = 30) {
    $this
      ->expireQueueItems();
    return parent::claimItem($lease_time);
  }

  /**
   * {@inheritdoc}
   */
  public function claimItemMultiple($claims = 10, $lease_time = 30) {
    $this
      ->expireQueueItems();
    return parent::claimItemMultiple($claims, $lease_time);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaPurgeQueueEfficient::$class_queue_item protected property The queue item class to spawn queue items with.
AcquiaPurgeQueueEfficient::$state protected property The state storage which holds the counter state items.
AcquiaPurgeQueueEfficient::bad public function Retrieve the failed purges counter. Overrides AcquiaPurgeQueueInterface::bad
AcquiaPurgeQueueEfficient::createItem public function Add a queue item and store it directly to the queue. Overrides SystemQueue::createItem
AcquiaPurgeQueueEfficient::createItemMultiple public function Add multiple items to the queue and store them efficiently. Overrides AcquiaPurgeQueueInterface::createItemMultiple
AcquiaPurgeQueueEfficient::deleteItemMultiple public function Delete multiple items from the queue at once. Overrides AcquiaPurgeQueueInterface::deleteItemMultiple
AcquiaPurgeQueueEfficient::deleteQueue public function Delete a queue and every item in the queue. Overrides SystemQueue::deleteQueue
AcquiaPurgeQueueEfficient::good public function Retrieve the successful purges counter. Overrides AcquiaPurgeQueueInterface::good
AcquiaPurgeQueueEfficient::numberOfItems public function Retrieve the number of items in the queue. Overrides SystemQueue::numberOfItems
AcquiaPurgeQueueEfficient::releaseItemMultiple public function Release multiple items that the worker could not process. Overrides AcquiaPurgeQueueInterface::releaseItemMultiple
AcquiaPurgeQueueEfficient::total public function Retrieve the total queue items counter. Overrides AcquiaPurgeQueueInterface::total
AcquiaPurgeQueueSmart::$ttl protected property Time in seconds Varnish is caching pages generated by Drupal.
AcquiaPurgeQueueSmart::claimItem public function SystemQueue::claimItem() doesn't included expired items in its query which means that it essentially breaks its own interface promise. Therefore we overload the implementation with one that does do this accurately. This should however flow back… Overrides AcquiaPurgeQueueEfficient::claimItem
AcquiaPurgeQueueSmart::claimItemMultiple public function Claims multiple items from the queue for processing. Overrides AcquiaPurgeQueueEfficient::claimItemMultiple
AcquiaPurgeQueueSmart::expireQueueItems protected function Expire queue items that should have already expired externally.
AcquiaPurgeQueueSmart::__construct public function Construct a AcquiaPurgeQueueSmart instance. Overrides AcquiaPurgeQueueEfficient::__construct
SystemQueue::$name protected property The name of the queue this instance is working with.
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::releaseItem public function Release an item that the worker could not process, so another worker can come in and process it before the timeout expires. Overrides DrupalQueueInterface::releaseItem