/**
  * Get the next item in the queue
  *
  * @return Irc_waiting_message Next message if there is one
  */
 public static function top()
 {
     $wm = new Irc_waiting_message();
     $wm->orderBy('prioritise DESC, created');
     $wm->whereAdd('claimed is null');
     $wm->limit(1);
     $cnt = $wm->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 IRC waiting message id = ' . $wm->id);
         $orig = clone $wm;
         $wm->claimed = common_sql_now();
         $result = $wm->update($orig);
         if ($result) {
             common_log(LOG_INFO, 'claim succeeded.');
             return $wm;
         } else {
             common_log(LOG_INFO, 'claim failed.');
         }
     }
     $wm = null;
     return null;
 }