diff options
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Queue_item.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/classes/Queue_item.php b/classes/Queue_item.php index a953e141b..2ae78d9f6 100644 --- a/classes/Queue_item.php +++ b/classes/Queue_item.php @@ -22,4 +22,34 @@ class Queue_item extends DB_DataObject ###END_AUTOCODE function sequenceKey() { return array(false, false); } + + static function top($transport) { + + $qi = new Queue_item(); + $qi->transport = $transport; + $qi->orderBy('created'); + $qi->whereAdd('claimed is NULL'); + + $qi->limit(1); + + $cnt = $qi->find(TRUE); + + if ($cnt) { + # XXX: potential race condition + # can we force it to only update if claimed is still NULL + # (or old)? + $this->log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id); + $orig = clone($qi); + $qi->claimed = common_sql_now(); + $result = $qi->update($orig); + if ($result) { + $this->log(LOG_INFO, 'claim succeeded.'); + return $qi; + } else { + $this->log(LOG_INFO, 'claim failed.'); + } + } + $qi = NULL; + return NULL; + } } |