]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Queue_item.php
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / classes / Queue_item.php
1 <?php
2 /**
3  * Table Definition for queue_item
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Queue_item extends Memcached_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'queue_item';                      // table name
13     public $notice_id;                       // int(4)  primary_key not_null
14     public $transport;                       // varchar(8)  primary_key not_null
15     public $created;                         // datetime()   not_null
16     public $claimed;                         // datetime()
17
18     /* Static get */
19     function staticGet($k,$v=null)
20     { return Memcached_DataObject::staticGet('Queue_item',$k,$v); }
21
22     /* the code above is auto generated do not remove the tag below */
23     ###END_AUTOCODE
24
25     function sequenceKey()
26     { return array(false, false); }
27
28     static function top($transport=null) {
29
30         $qi = new Queue_item();
31         if ($transport) {
32             $qi->transport = $transport;
33         }
34         $qi->orderBy('created');
35         $qi->whereAdd('claimed is null');
36
37         $qi->limit(1);
38
39         $cnt = $qi->find(true);
40
41         if ($cnt) {
42             # XXX: potential race condition
43             # can we force it to only update if claimed is still null
44             # (or old)?
45             common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id .
46                 ' for transport ' . $qi->transport);
47             $orig = clone($qi);
48             $qi->claimed = common_sql_now();
49             $result = $qi->update($orig);
50             if ($result) {
51                 common_log(LOG_INFO, 'claim succeeded.');
52                 return $qi;
53             } else {
54                 common_log(LOG_INFO, 'claim failed.');
55             }
56         }
57         $qi = null;
58         return null;
59     }
60
61     function pkeyGet($kv)
62     {
63         return Memcached_DataObject::pkeyGet('Queue_item', $kv);
64     }
65 }