3 * Table Definition for queue_item
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Queue_item extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'queue_item'; // table name
13 public $id; // int(4) primary_key not_null
14 public $frame; // blob not_null
15 public $created; // datetime() not_null
16 public $claimed; // datetime()
19 function staticGet($k,$v=null)
20 { return Memcached_DataObject::staticGet('Queue_item',$k,$v); }
22 /* the code above is auto generated do not remove the tag below */
25 public static function schemaDef()
29 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
30 'frame' => array('type' => 'blob', 'not null' => true, 'description' => 'data: object reference or opaque string'),
31 'transport' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'queue for what? "email", "xmpp", "sms", "irc", ...'), // @fixme 8 chars is too short; bump up.
32 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
33 'claimed' => array('type' => 'datetime', 'description' => 'date this item was claimed'),
35 'primary key' => array('id'),
37 'queue_item_created_idx' => array('created'),
43 * @param mixed $transports name of a single queue or array of queues to pull from
44 * If not specified, checks all queues in the system.
46 static function top($transports=null) {
48 $qi = new Queue_item();
50 if (is_array($transports)) {
51 // @fixme use safer escaping
52 $list = implode("','", array_map(array($qi, 'escape'), $transports));
53 $qi->whereAdd("transport in ('$list')");
55 $qi->transport = $transports;
58 $qi->orderBy('created');
59 $qi->whereAdd('claimed is null');
63 $cnt = $qi->find(true);
66 // XXX: potential race condition
67 // can we force it to only update if claimed is still null
69 common_log(LOG_INFO, 'claiming queue item id = ' . $qi->id .
70 ' for transport ' . $qi->transport);
72 $qi->claimed = common_sql_now();
73 $result = $qi->update($orig);
75 common_log(LOG_INFO, 'claim succeeded.');
78 common_log(LOG_INFO, 'claim failed.');
86 * Release a claimed item.
88 function releaseCLaim()
90 // DB_DataObject doesn't let us save nulls right now
91 $sql = sprintf("UPDATE queue_item SET claimed=NULL WHERE id=%d", $this->id);
94 $this->claimed = null;