2008-07-04 13:07:46 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Table Definition for queue_item
|
|
|
|
*/
|
|
|
|
require_once 'DB/DataObject.php';
|
|
|
|
|
2008-07-16 04:55:13 +09:00
|
|
|
class Queue_item extends DB_DataObject
|
2008-07-04 13:07:46 +09: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-28 06:12:39 +09:00
|
|
|
public $transport; // varchar(8) primary_key not_null
|
2008-07-04 13:07:46 +09:00
|
|
|
public $created; // datetime() not_null
|
2008-07-16 04:55:13 +09:00
|
|
|
public $claimed; // datetime()
|
2008-07-04 13:07:46 +09: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-10 07:46:30 +09:00
|
|
|
|
2008-07-04 17:24:18 +09:00
|
|
|
function sequenceKey() { return array(false, false); }
|
2008-08-28 05:54:07 +09: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 09:45:03 +09:00
|
|
|
common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id);
|
2008-08-28 05:54:07 +09:00
|
|
|
$orig = clone($qi);
|
|
|
|
$qi->claimed = common_sql_now();
|
|
|
|
$result = $qi->update($orig);
|
|
|
|
if ($result) {
|
2008-08-28 09:45:03 +09:00
|
|
|
common_log(LOG_INFO, 'claim succeeded.');
|
2008-08-28 05:54:07 +09:00
|
|
|
return $qi;
|
|
|
|
} else {
|
2008-08-28 09:45:03 +09:00
|
|
|
common_log(LOG_INFO, 'claim failed.');
|
2008-08-28 05:54:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$qi = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-07-04 13:07:46 +09:00
|
|
|
}
|