We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Queue_item.php 1.74 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1 2 3 4
<?php
/**
 * Table Definition for queue_item
 */
5
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
Evan Prodromou's avatar
Evan Prodromou committed
6

7
class Queue_item extends Memcached_DataObject 
Evan Prodromou's avatar
Evan Prodromou committed
8 9 10 11 12 13
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    public $__table = 'queue_item';                      // table name
    public $notice_id;                       // int(4)  primary_key not_null
14
    public $transport;                       // varchar(8)  primary_key not_null
Evan Prodromou's avatar
Evan Prodromou committed
15
    public $created;                         // datetime()   not_null
16
    public $claimed;                         // datetime()  
Evan Prodromou's avatar
Evan Prodromou committed
17 18

    /* Static get */
Evan Prodromou's avatar
Evan Prodromou committed
19
    function staticGet($k,$v=null) { return Memcached_DataObject::staticGet('Queue_item',$k,$v); }
Evan Prodromou's avatar
Evan Prodromou committed
20 21 22

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE
23

24
    function sequenceKey() { return array(false, false); }
25 26 27 28 29 30
    
    static function top($transport) {

        $qi = new Queue_item();
        $qi->transport = $transport;
        $qi->orderBy('created');
Evan Prodromou's avatar
Evan Prodromou committed
31
        $qi->whereAdd('claimed is null');
32 33 34 35 36 37 38

        $qi->limit(1);

        $cnt = $qi->find(TRUE);

        if ($cnt) {
            # XXX: potential race condition
Evan Prodromou's avatar
Evan Prodromou committed
39
            # can we force it to only update if claimed is still null
40 41 42 43 44 45 46 47 48 49 50 51
            # (or old)?
            common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport);
            $orig = clone($qi);
            $qi->claimed = common_sql_now();
            $result = $qi->update($orig);
            if ($result) {
                common_log(LOG_INFO, 'claim succeeded.');
                return $qi;
            } else {
                common_log(LOG_INFO, 'claim failed.');
            }
        }
Evan Prodromou's avatar
Evan Prodromou committed
52 53
        $qi = null;
        return null;
54
    }
Evan Prodromou's avatar
Evan Prodromou committed
55
}