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()
18 /* the code above is auto generated do not remove the tag below */
21 public static function schemaDef()
25 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
26 'frame' => array('type' => 'blob', 'not null' => true, 'description' => 'data: object reference or opaque string'),
27 '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.
28 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
29 'claimed' => array('type' => 'datetime', 'description' => 'date this item was claimed'),
31 'primary key' => array('id'),
33 'queue_item_created_idx' => array('created'),
39 * @param mixed $transports name of a single queue or array of queues to pull from
40 * If not specified, checks all queues in the system.
42 static function top($transports=null) {
44 $qi = new Queue_item();
46 if (is_array($transports)) {
47 // @fixme use safer escaping
48 $list = implode("','", array_map(array($qi, 'escape'), $transports));
49 $qi->whereAdd("transport in ('$list')");
51 $qi->transport = $transports;
54 $qi->orderBy('created');
55 $qi->whereAdd('claimed is null');
59 $cnt = $qi->find(true);
62 // XXX: potential race condition
63 // can we force it to only update if claimed is still null
65 common_log(LOG_INFO, 'claiming queue item id = ' . $qi->id .
66 ' for transport ' . $qi->transport);
68 $qi->claimed = common_sql_now();
69 $result = $qi->update($orig);
71 common_log(LOG_INFO, 'claim succeeded.');
74 common_log(LOG_INFO, 'claim failed.');
82 * Release a claimed item.
84 function releaseCLaim()
86 // DB_DataObject doesn't let us save nulls right now
87 $sql = sprintf("UPDATE queue_item SET claimed=NULL WHERE id=%d", $this->id);
90 $this->claimed = null;