123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
- class Irc_waiting_message extends Managed_DataObject {
- public $__table = 'irc_waiting_message';
- public $id;
- public $data;
- public $prioritise;
- public $attempts;
- public $claimed;
- public $created;
- public $modified;
- public static function schemaDef()
- {
- return array(
- 'fields' => array(
- 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for entry'),
- 'data' => array('type' => 'blob', 'not null' => true, 'description' => 'data blob'),
- 'prioritise' => array('type' => 'int', 'size' => 'tiny', 'description' => 'tinyint priority value'),
- 'attempts' => array('type' => 'int', 'not null' => true, 'description' => 'attempts count'),
- 'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),
- 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
- 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
- ),
- 'primary key' => array('id'),
- 'indexes' => array(
- 'irc_waiting_message_prioritise_idx' => array('prioritise'),
- ),
- );
- }
-
- 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) {
-
-
-
- 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;
- }
-
- public function incAttempts() {
- $orig = clone($this);
- $this->attempts++;
- $result = $this->update($orig);
- if (!$result) {
-
-
- throw new Exception(sprintf(_m('Could not increment attempts count for %d.'), $this->id));
- }
- }
-
- public function releaseClaim() {
-
- $sql = sprintf("UPDATE irc_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
- $this->query($sql);
- $this->claimed = null;
- $this->encache();
- }
- }
|