]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Queue_item.php
path correct in require_once for memcached
[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) { return Memcached_DataObject::staticGet('Queue_item',$k,$v); }
20
21     /* the code above is auto generated do not remove the tag below */
22     ###END_AUTOCODE
23
24     function sequenceKey() { return array(false, false); }
25         
26         static function top($transport) {
27
28                 $qi = new Queue_item();
29                 $qi->transport = $transport;
30                 $qi->orderBy('created');
31                 $qi->whereAdd('claimed is NULL');
32
33                 $qi->limit(1);
34
35                 $cnt = $qi->find(TRUE);
36
37                 if ($cnt) {
38                         # XXX: potential race condition
39                         # can we force it to only update if claimed is still NULL
40                         # (or old)?
41                         common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport);
42                         $orig = clone($qi);
43                         $qi->claimed = common_sql_now();
44                         $result = $qi->update($orig);
45                         if ($result) {
46                                 common_log(LOG_INFO, 'claim succeeded.');
47                                 return $qi;
48                         } else {
49                                 common_log(LOG_INFO, 'claim failed.');
50                         }
51                 }
52                 $qi = NULL;
53                 return NULL;
54         }
55 }