2008-07-04 05:07:46 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Table Definition for queue_item
|
|
|
|
*/
|
|
|
|
require_once 'DB/DataObject.php';
|
|
|
|
|
2008-07-15 20:55:13 +01:00
|
|
|
class Queue_item extends DB_DataObject
|
2008-07-04 05:07:46 +01:00
|
|
|
{
|
|
|
|
###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
|
2008-08-27 22:12:39 +01:00
|
|
|
public $transport; // varchar(8) primary_key not_null
|
2008-07-04 05:07:46 +01:00
|
|
|
public $created; // datetime() not_null
|
2008-07-15 20:55:13 +01:00
|
|
|
public $claimed; // datetime()
|
2008-07-04 05:07:46 +01:00
|
|
|
|
|
|
|
/* Static get */
|
|
|
|
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Queue_item',$k,$v); }
|
|
|
|
|
|
|
|
/* the code above is auto generated do not remove the tag below */
|
|
|
|
###END_AUTOCODE
|
2008-07-09 23:46:30 +01:00
|
|
|
|
2008-07-04 09:24:18 +01:00
|
|
|
function sequenceKey() { return array(false, false); }
|
2008-08-27 21:54:07 +01:00
|
|
|
|
|
|
|
static function top($transport) {
|
|
|
|
|
|
|
|
$qi = new Queue_item();
|
|
|
|
$qi->transport = $transport;
|
|
|
|
$qi->orderBy('created');
|
|
|
|
$qi->whereAdd('claimed is NULL');
|
|
|
|
|
|
|
|
$qi->limit(1);
|
|
|
|
|
|
|
|
$cnt = $qi->find(TRUE);
|
|
|
|
|
|
|
|
if ($cnt) {
|
|
|
|
# XXX: potential race condition
|
|
|
|
# can we force it to only update if claimed is still NULL
|
|
|
|
# (or old)?
|
2008-08-28 01:45:03 +01:00
|
|
|
common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id);
|
2008-08-27 21:54:07 +01:00
|
|
|
$orig = clone($qi);
|
|
|
|
$qi->claimed = common_sql_now();
|
|
|
|
$result = $qi->update($orig);
|
|
|
|
if ($result) {
|
2008-08-28 01:45:03 +01:00
|
|
|
common_log(LOG_INFO, 'claim succeeded.');
|
2008-08-27 21:54:07 +01:00
|
|
|
return $qi;
|
|
|
|
} else {
|
2008-08-28 01:45:03 +01:00
|
|
|
common_log(LOG_INFO, 'claim failed.');
|
2008-08-27 21:54:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$qi = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-07-04 05:07:46 +01:00
|
|
|
}
|