yf_wrapper_queue class

Core queue wrapper.

Fileplugins/queue/classes/yf_wrapper_queue.class.php
Use_class('wrapper_queue')

Public properties

A site sets them in its config with $PROJECT_CONF['wrapper_queue']['NAME'] = ...;

PropertyDefaultDescription
$_connection null
$driver 'redis'

Public methods 9

add

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);
    }

all

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);
    }

conf

public function conf($params = [])

Configure driver.

    public function conf($params = [])
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->conf($params);
    }

connect

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;
    }

del

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);
    }

get

public function get($queue)

Get one item from named queue (dequeue).

    public function get($queue)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->get($queue);
    }

is_ready

public function is_ready()

Check if queue system is ready for processing.

    public function is_ready()
    {
        ! $this->_connection && $this->connect();
        return (bool) $this->_connection;
    }

listen

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);
        }
    }

Methods starting with _ hooks and helpers; not routable as page actions

__call

public 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);
    }