Class zhuravljov\yii\queue\db\Driver
Inheritance | zhuravljov\yii\queue\db\Driver » zhuravljov\yii\queue\BaseDriver » yii\base\Object |
---|---|
Implements | yii\base\BootstrapInterface |
Source Code | https://github.com/yiisoft/yii2-queue/blob/master/src/db/Driver.php |
Class DbDriver
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$db | \yii\db\Connection|array|string | zhuravljov\yii\queue\db\Driver | |
$mutex | \yii\mutex\Mutex|array|string | zhuravljov\yii\queue\db\Driver | |
$queue | zhuravljov\yii\queue\Queue | zhuravljov\yii\queue\BaseDriver | |
$tableName | string | Table name | zhuravljov\yii\queue\db\Driver |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | zhuravljov\yii\queue\BaseDriver | |
bootstrap() | zhuravljov\yii\queue\db\Driver | |
init() | zhuravljov\yii\queue\db\Driver | |
pop() | Pops message and job from the storage. | zhuravljov\yii\queue\db\Driver |
purge() | Purges the storage. | zhuravljov\yii\queue\db\Driver |
push() | Pushes job to the storage. | zhuravljov\yii\queue\db\Driver |
release() | Releases the message. | zhuravljov\yii\queue\db\Driver |
Protected Methods
Method | Description | Defined By |
---|---|---|
getQueue() | zhuravljov\yii\queue\BaseDriver |
Property Details
Method Details
Defined in: zhuravljov\yii\queue\BaseDriver::__construct()
public void __construct ( zhuravljov\yii\queue\Queue $queue, $config = [] ) | ||
$queue | zhuravljov\yii\queue\Queue | |
$config |
public function __construct(Queue $queue, $config = [])
{
$this->_queue = $queue;
parent::__construct($config);
}
public void bootstrap ( $app ) | ||
$app |
public function bootstrap($app)
{
if ($app instanceof \yii\console\Application) {
$app->controllerMap[$this->queue->id] = [
'class' => Command::class,
'queue' => $this->queue,
];
}
}
Defined in: zhuravljov\yii\queue\BaseDriver::getQueue()
protected zhuravljov\yii\queue\Queue getQueue ( ) |
protected function getQueue()
{
return $this->_queue;
}
public void init ( ) |
public function init()
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::class);
$this->mutex = Instance::ensure($this->mutex, Mutex::class);
}
Pops message and job from the storage.
public boolean pop ( &$message, &$job ) | ||
$message | mixed | |
$job | zhuravljov\yii\queue\Job |
public function pop(&$message, &$job)
{
$this->mutex->acquire(__CLASS__);
$message = (new Query())
->from($this->tableName)
->where(['started_at' => null])
->orderBy(['id' => SORT_ASC])
->limit(1)
->one($this->db);
if (is_array($message)) {
$message['started_at'] = time();
$this->db->createCommand()->update(
$this->tableName,
['started_at' => $message['started_at']],
['id' => $message['id']]
)->execute();
}
$this->mutex->release(__CLASS__);
if (is_array($message)) {
$job = unserialize($message['job']);
return true;
} else {
return false;
}
}
Purges the storage.
public void purge ( ) |
public function purge()
{
$this->mutex->acquire(__CLASS__);
$this->db->createCommand()->delete(
$this->tableName,
['started_at' => null]
)->execute();
$this->mutex->release(__CLASS__);
}
Pushes job to the storage.
public mixed push ( $job ) | ||
$job | zhuravljov\yii\queue\Job | |
return | mixed |
$message |
---|
public function push($job)
{
$this->db->createCommand()->insert(
$this->tableName,
['job' => serialize($job), 'created_at' => time()]
)->execute();
return (new Query())
->from($this->tableName)
->where(['id' => $this->db->lastInsertID])
->one($this->db);
}
Releases the message.
public void release ( $message ) | ||
$message |
public function release($message)
{
$this->db->createCommand()->update(
$this->tableName,
['finished_at' => time()],
['id' => $message['id']]
)->execute();
}