Class zhuravljov\yii\queue\Queue
| Inheritance | zhuravljov\ |
|---|---|
| Implements | yii\ |
| Source Code | https://github.com/yiisoft/yii2-queue/blob/master/src/Queue.php |
Class Queue
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $driver | zhuravljov\ |
zhuravljov\ |
|
| $id | string | of component | zhuravljov\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| bootstrap() | zhuravljov\ |
|
| getId() | zhuravljov\ |
|
| init() | zhuravljov\ |
|
| purge() | Purges the queue | zhuravljov\ |
| push() | zhuravljov\ |
|
| work() | zhuravljov\ |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| EVENT_ON_POP | 'onPop' | zhuravljov\ |
|
| EVENT_ON_PUSH | 'onPush' | zhuravljov\ |
|
| EVENT_ON_RELEASE | 'onRelease' | zhuravljov\ |
Property Details
Method Details
| public bootstrap ( mixed $app ) | ||
| $app | mixed | |
public function bootstrap($app)
{
if ($this->driver instanceof BootstrapInterface) {
$this->driver->bootstrap($app);
}
}
| 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;
}
| public init ( ) |
public function init()
{
parent::init();
$this->driver = Yii::createObject($this->driver, [$this]);
}
| public mixed push ( zhuravljov\ | ||
| $job | zhuravljov\ |
|
public function push(Job $job)
{
$this->driver->push($job);
$this->trigger(self::EVENT_ON_PUSH, new Event(['job' => $job]));
}
| public boolean work ( boolean $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;
}
}