3 * Table Definition for irc_waiting_message
\r
6 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
\r
8 class Irc_waiting_message extends Managed_DataObject {
\r
10 public $__table = 'irc_waiting_message'; // table name
\r
11 public $id; // int primary_key not_null auto_increment
\r
12 public $data; // blob not_null
\r
13 public $prioritise; // tinyint(1) not_null
\r
14 public $attempts; // int not_null
\r
15 public $claimed; // datetime()
\r
16 public $created; // datetime() not_null
\r
17 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
\r
19 public static function schemaDef()
\r
23 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for entry'),
\r
24 'data' => array('type' => 'blob', 'not null' => true, 'description' => 'data blob'),
\r
25 'prioritise' => array('type' => 'int', 'size' => 'tiny', 'description' => 'tinyint priority value'),
\r
26 'attempts' => array('type' => 'int', 'not null' => true, 'description' => 'attempts count'),
\r
27 'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),
\r
28 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
\r
29 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
\r
31 'primary key' => array('id'),
\r
33 'irc_waiting_message_prioritise_idx' => array('prioritise'),
\r
39 * Get the next item in the queue
\r
41 * @return Irc_waiting_message Next message if there is one
\r
43 public static function top() {
\r
44 $wm = new Irc_waiting_message();
\r
46 $wm->orderBy('prioritise DESC, created');
\r
47 $wm->whereAdd('claimed is null');
\r
51 $cnt = $wm->find(true);
\r
54 // XXX: potential race condition
\r
55 // can we force it to only update if claimed is still null
\r
57 common_log(LOG_INFO, 'claiming IRC waiting message id = ' . $wm->id);
\r
59 $wm->claimed = common_sql_now();
\r
60 $result = $wm->update($orig);
\r
62 common_log(LOG_INFO, 'claim succeeded.');
\r
65 common_log(LOG_INFO, 'claim failed.');
\r
73 * Increment the attempts count
\r
78 public function incAttempts() {
\r
79 $orig = clone($this);
\r
81 $result = $this->update($orig);
\r
84 // TRANS: Exception thrown when an IRC attempts count could not be updated.
\r
85 // TRANS: %d is the object ID for which the count could not be updated.
\r
86 throw Exception(sprintf(_m('Could not increment attempts count for %d.'), $this->id));
\r
91 * Release a claimed item.
\r
93 public function releaseClaim() {
\r
94 // DB_DataObject doesn't let us save nulls right now
\r
95 $sql = sprintf("UPDATE irc_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
\r
98 $this->claimed = null;
\r