yf_wrapper_queue classCore queue wrapper.
| File | plugins/queue/classes/yf_wrapper_queue.class.php |
|---|---|
| Use | _class('wrapper_queue') |
A site sets them in its config with $PROJECT_CONF['wrapper_queue']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$_connection |
null |
|
$driver |
'redis' |
public function add($queue, $what)
Add new item into named queue.
public function add($queue, $what)
{
! $this->_connection && $this->connect();
return $this->_connection->add($queue, $what);
}
public function all($queue)
Return all data from the queue, but not ewmo (for debug purposes).
public function all($queue)
{
! $this->_connection && $this->connect();
return $this->_connection->all($queue);
}
public function conf($params = [])
Configure driver.
public function conf($params = [])
{
! $this->_connection && $this->connect();
return $this->_connection->conf($params);
}
public function connect()
Do connect to the low level driver.
public function connect()
{
if ( ! $this->_connection) {
$this->_connection = _class('queue_driver_' . $this->driver, 'classes/queue/');
$this->_connection->connect();
}
return $this->_connection;
}
public function del($queue = false)
Delete one item from the queue.
public function del($queue = false)
{
! $this->_connection && $this->connect();
return $this->_connection->del($queue);
}
public function get($queue)
Get one item from named queue (dequeue).
public function get($queue)
{
! $this->_connection && $this->connect();
return $this->_connection->get($queue);
}
public function is_ready()
Check if queue system is ready for processing.
public function is_ready()
{
! $this->_connection && $this->connect();
return (bool) $this->_connection;
}
public function listen($qname, $callback, $params = [])
Listen to queue.
public function listen($qname, $callback, $params = [])
{
if ( ! $this->is_ready()) {
return false;
}
while (true) {
$data = $this->get($qname);
if ($data) {
$callback($data, $params);
}
usleep(($params['usleep'] ?? null) ?: 100000);
}
}
_ hooks and helpers; not routable as page actionspublic function __call($name, $args)
Catch missing method call.
public function __call($name, $args)
{
! $this->_connection && $this->connect();
// Support for driver-specific methods
if (is_object($this->_connection) && method_exists($this->_connection, $name)) {
return call_user_func_array([$this->_connection, $name], $args);
}
return main()->extend_call($this, $name, $args);
}