diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-08 06:36:34 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-08 06:36:34 +0000 |
commit | 0dd161277046bab1ec994e8d756c4e99c717421e (patch) | |
tree | 5f33a4f472b6b5e10544924e5bf6cfc0348b8d08 /includes/batch.queue.inc | |
parent | e07b9d35a1f4dcb1678c4d3bb6482daaebea6350 (diff) | |
download | brdo-0dd161277046bab1ec994e8d756c4e99c717421e.tar.gz brdo-0dd161277046bab1ec994e8d756c4e99c717421e.tar.bz2 |
#629794 by yched: Fix Scaling issues with batch API. (with tests)
Diffstat (limited to 'includes/batch.queue.inc')
-rw-r--r-- | includes/batch.queue.inc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/includes/batch.queue.inc b/includes/batch.queue.inc new file mode 100644 index 000000000..8193280f3 --- /dev/null +++ b/includes/batch.queue.inc @@ -0,0 +1,72 @@ +<?php +// $Id$ + + +/** + * @file + * Queue handlers used by the Batch API. + * + * Those implementations: + * - ensure FIFO ordering, + * - let an item be repeatedly claimed until it is actually deleted (no notion + * of lease time or 'expire' date), to allow multipass operations. + */ + +/** + * Batch queue implementation. + * + * Stale items from failed batches are cleaned from the {queue} table on cron + * using the 'created' date. + */ +class BatchQueue extends SystemQueue { + + public function claimItem($lease_time = 0) { + $item = db_query('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchObject(); + if ($item) { + $item->data = unserialize($item->data); + return $item; + } + return FALSE; + } + + /** + * Retrieve all remaining items in the queue. + * + * This is specific to Batch API and is not part of the DrupalQueueInterface, + */ + public function getAllItems() { + $result = array(); + $items = db_query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchAll(); + foreach ($items as $item) { + $result[] = unserialize($item->data); + } + return $result; + } +} + +/** + * Batch queue implementation used for non-progressive batches. + */ +class BatchMemoryQueue extends MemoryQueue { + + public function claimItem($lease_time = 0) { + if (!empty($this->queue)) { + reset($this->queue); + return current($this->queue); + } + return FALSE; + } + + /** + * Retrieve all remaining items in the queue. + * + * This is specific to Batch API and is not part of the DrupalQueueInterface, + */ + public function getAllItems() { + $result = array(); + foreach ($this->queue as $item) { + $result[] = $item->data; + } + return $result; + } +} |