Class zhuravljov\yii\queue\db\Driver
| Inheritance | zhuravljov\ |
|---|---|
| Implements | yii\ |
| Source Code | https://github.com/yiisoft/yii2-queue/blob/master/src/db/Driver.php |
Class DbDriver
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $db | \ |
zhuravljov\ |
|
| $deleteReleased | boolean | Ability to delete released messages from table | zhuravljov\ |
| $mutex | \ |
zhuravljov\ |
|
| $queue | zhuravljov\ |
zhuravljov\ |
|
| $tableName | string | Table name | zhuravljov\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | zhuravljov\ |
|
| bootstrap() | zhuravljov\ |
|
| init() | zhuravljov\ |
|
| pop() | Pops message and job from the storage. | zhuravljov\ |
| purge() | Purges the storage. | zhuravljov\ |
| push() | Pushes job to the storage. | zhuravljov\ |
| release() | Releases the message. | zhuravljov\ |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| getQueue() | zhuravljov\ |
Property Details
Ability to delete released messages from table
Method Details
Defined in:
zhuravljov\
| public __construct ( zhuravljov\ | ||
| $queue | zhuravljov\ |
|
| $config | mixed | |
public function __construct(Queue $queue, $config = [])
{
$this->_queue = $queue;
parent::__construct($config);
}
| public bootstrap ( mixed $app ) | ||
| $app | mixed | |
public function bootstrap($app)
{
if ($app instanceof \yii\console\Application) {
$app->controllerMap[$this->queue->id] = [
'class' => Command::class,
'queue' => $this->queue,
];
}
}
Defined in:
zhuravljov\
| protected zhuravljov\ |
protected function getQueue()
{
return $this->_queue;
}
| public mixed 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 ( mixed &$message, mixed &$job ) | ||
| $message | mixed | |
| $job | mixed | |
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 mixed 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 ( mixed $job ) | ||
| $job | mixed | |
| 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 mixed release ( mixed $message ) | ||
| $message | mixed | |
public function release($message)
{
if ($this->deleteReleased) {
$this->db->createCommand()->delete(
$this->tableName,
['id' => $message['id']]
)->execute();
} else {
$this->db->createCommand()->update(
$this->tableName,
['finished_at' => time()],
['id' => $message['id']]
)->execute();
}
}