コード例 #1
0
ファイル: ircmanager.php プロジェクト: Grasia/bolotweet
 /**
  * Enters a message into the database for sending when ready
  *
  * @param string $command Command
  * @param array $args Arguments
  * @return boolean
  */
 protected function enqueue_waiting_message($data)
 {
     $wm = new Irc_waiting_message();
     $wm->data = serialize($data);
     $wm->prioritise = $data['prioritise'];
     $wm->attempts = 0;
     $wm->created = common_sql_now();
     $result = $wm->insert();
     if (!$result) {
         common_log_db_error($wm, 'INSERT', __FILE__);
         // TRANS: Server exception thrown when an IRC waiting queue item could not be added to the database.
         throw new ServerException(_m('Database error inserting IRC waiting queue item.'));
     }
     return true;
 }
コード例 #2
0
 /**
  * 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;
 }