Commit 7cfb1157 authored by Dries's avatar Dries

Issue #1928056 by pwolanin: Queue system createItem() should return ID, and ...

Issue #1928056 by pwolanin: Queue system createItem() should return ID, and  properties should be documented.
parent d22f1cbb
......@@ -53,7 +53,8 @@ public function createItem($data) {
// by a single request which takes longer than 1 second.
'created' => time(),
));
return (bool) $query->execute();
// Return the new serial ID, or FALSE on failure.
return $query->execute();
}
/**
......@@ -72,7 +73,7 @@ public function claimItem($lease_time = 30) {
// until an item is successfully claimed or we are reasonably sure there
// are no unclaimed items left.
while (TRUE) {
$item = $this->connection->queryRange('SELECT data, item_id FROM {queue} q WHERE expire = 0 AND name = :name ORDER BY created ASC', 0, 1, array(':name' => $this->name))->fetchObject();
$item = $this->connection->queryRange('SELECT data, created, item_id FROM {queue} q WHERE expire = 0 AND name = :name ORDER BY created ASC', 0, 1, array(':name' => $this->name))->fetchObject();
if ($item) {
// Try to update the item. Only one thread can succeed in UPDATEing the
// same row. We cannot rely on REQUEST_TIME because items might be
......
......@@ -52,6 +52,7 @@ public function createItem($data) {
$item->created = time();
$item->expire = 0;
$this->queue[$item->item_id] = $item;
return $item->item_id;
}
/**
......
......@@ -22,8 +22,8 @@ interface QueueInterface {
* Arbitrary data to be associated with the new task in the queue.
*
* @return
* TRUE if the item was successfully created and was (best effort) added
* to the queue, otherwise FALSE. We don't guarantee the item was
* A unique ID if the item was successfully created and was (best effort)
* added to the queue, otherwise FALSE. We don't guarantee the item was
* committed to disk etc, but as far as we know, the item is now in the
* queue.
*/
......@@ -63,6 +63,11 @@ public function numberOfItems();
* item it returns false. This implies a best effort to retrieve an item
* and either the queue is empty or there is some other non-recoverable
* problem.
*
* If returned, the object will have at least the following properties:
* - data: the same as what what passed into createItem().
* - item_id: the unique ID returned from createItem().
* - created: timestamp when the item was put into the queue.
*/
public function claimItem($lease_time = 3600);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment