Class zhuravljov\yii\queue\Queue

Inheritancezhuravljov\yii\queue\Queue » yii\base\Component
Implementsyii\base\BootstrapInterface
Source Code https://github.com/yiisoft/yii2-queue/blob/master/src/Queue.php

Class Queue

Constants

Hide inherited constants

Constant Value Description Defined By
EVENT_ON_POP 'onPop' zhuravljov\yii\queue\Queue
EVENT_ON_PUSH 'onPush' zhuravljov\yii\queue\Queue
EVENT_ON_RELEASE 'onRelease' zhuravljov\yii\queue\Queue

Property Details

Hide inherited properties

$driver public property
$id public property

of component

public string $id null

Method Details

Hide inherited methods

bootstrap() public method

public void bootstrap ( $app )
$app

                public function bootstrap($app)
{
    if ($this->driver instanceof BootstrapInterface) {
        $this->driver->bootstrap($app);
    }
}

            
getId() public method

public string getId ( )
return string

Component id

                public function getId()
{
    foreach (Yii::$app->getComponents(false) as $id => $component) {
        if ($component === $this) {
            return $id;
        }
    }
    return null;
}

            
init() public method

public void init ( )

                public function init()
{
    parent::init();
    $this->driver = Yii::createObject($this->driver, [$this]);
}

            
purge() public method

Purges the queue

public void purge ( )

                public function purge()
{
    $this->driver->purge();
}

            
push() public method

public void push ( zhuravljov\yii\queue\Job $job )
$job zhuravljov\yii\queue\Job

                public function push(Job $job)
{
    $this->driver->push($job);
    $this->trigger(self::EVENT_ON_PUSH, new Event(['job' => $job]));
}

            
work() public method

public boolean work ( $throw true )
$throw boolean

                public function work($throw = true)
{
    if ($this->driver->pop($message, $job)) {
        $this->trigger(self::EVENT_ON_POP, new Event(['job' => $job]));
        try {
            /** @var Job $job */
            $job->run($this);
        } catch (\Exception $e) {
            if ($throw) {
                throw $e;
            } else {
                Yii::error($e, __METHOD__);
            }
        } finally {
            $this->driver->release($message);
            $this->trigger(self::EVENT_ON_RELEASE, new Event(['job' => $job]));
        }
        return true;
    } else {
        return false;
    }
}