View source
<?php
class ComputingQueue implements DrupalReliableQueueInterface {
protected $app_name;
private function __construct($app_name) {
$this->app_name = $app_name;
}
public static function get($app_name) {
static $queues;
if (!isset($queues[$app_name])) {
$object = new ComputingQueue($app_name);
$queues[$app_name] = $object;
}
return $queues[$app_name];
}
public function createItem($data) {
if (is_object($data)) {
$data = (array) $data;
}
$options = array_diff_key($data, array_flip(array(
'application',
'command',
'label',
'input',
)));
return (bool) computing_create($data['application'], $data['command'], $data['label'], $data['input'], $options);
}
public function numberOfItems() {
return db_query("SELECT COUNT(id) FROM {computing_record} WHERE application = :name AND status = 'RDY'", array(
':name' => $this->app_name,
))
->fetchField();
}
public function claimItem($lease_time = 3600) {
return computing_claim($this->app_name);
}
public function deleteItem($item) {
if (!is_object($item)) {
$item = (object) $item;
}
if (computing_update_field($item->id, 'status', 'ABD')) {
return computing_load($item->id);
}
else {
return FALSE;
}
}
public function releaseItem($item) {
if (!is_object($item)) {
$item = (object) $item;
}
return computing_release($item->id);
}
public function createQueue() {
}
public function deleteQueue() {
}
}