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)? common_log(LOG_INFO, 'claiming queue item id=' . $qi->id . ' for transport ' . $qi->transport); $orig = clone($qi); $qi->claimed = common_sql_now(); $result = $qi->update($orig); if ($result) { common_log(LOG_INFO, 'claim succeeded.'); return $qi; } else { common_log(LOG_INFO, 'claim failed.'); } } $qi = null; return null; } }