PHP Class UrbanIndo\Yii2\Queue\Queues\DbQueue

The schema of the table should follow: CREATE TABLE queue ( id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, status TINYINT NOT NULL DEFAULT 0, timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, data BLOB ); The queue works under the asumption that the id fields is AUTO_INCREMENT and the timestamp will be set using current timestamp. For other implementation, override the fetchLatestRow method and postJob method.
Since: 2016.01.16
Author: Petra Barus ([email protected])
Inheritance: extends UrbanIndo\Yii2\Queue\Queue
Show file Open project: urbanindo/yii2-queue

Public Properties

Property Type Description
$db string | yii\db\Connection This will use default db component from Yii application.
$hardDelete boolean Whether to do hard delete of the deleted job, instead of just flagging the status.
$tableName string The table should be pre-created as follows for MySQL: php CREATE TABLE queue ( id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, status TINYINT NOT NULL DEFAULT 0, timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, data LONGBLOB );

Public Methods

Method Description
deleteJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Delete the job. Override this for the queue implementation.
getSize ( ) : integer Returns the number of queue size.
init ( ) : void
purge ( ) : boolean Purge the whole queue.
releaseJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Restore job from active to ready.

Protected Methods

Method Description
fetchJob ( ) : UrbanIndo\Yii2\Queue\Job | boolean Return next job from the queue.
fetchLatestRow ( ) : array Fetch latest ready job from the table.
flagRunningRow ( array $row ) : boolean Flag a row as running. This will update the row ID and status if ready.
postJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Post new job to the queue. This contains implementation for database.

Method Details

deleteJob() public method

Delete the job. Override this for the queue implementation.
public deleteJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job to delete.
return boolean whether the operation succeed.

fetchJob() protected method

Return next job from the queue.
protected fetchJob ( ) : UrbanIndo\Yii2\Queue\Job | boolean
return UrbanIndo\Yii2\Queue\Job | boolean the job or false if not found.

fetchLatestRow() protected method

Due to the use of AUTO_INCREMENT ID, this will fetch the job with the largest ID.
protected fetchLatestRow ( ) : array
return array

flagRunningRow() protected method

Flag a row as running. This will update the row ID and status if ready.
protected flagRunningRow ( array $row ) : boolean
$row array The row to update.
return boolean Whether successful or not.

getSize() public method

Returns the number of queue size.
public getSize ( ) : integer
return integer

init() public method

public init ( ) : void
return void

postJob() protected method

Post new job to the queue. This contains implementation for database.
protected postJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job to post.
return boolean whether operation succeed.

purge() public method

Purge the whole queue.
public purge ( ) : boolean
return boolean

releaseJob() public method

Restore job from active to ready.
public releaseJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job to restore.
return boolean whether the operation succeed.

Property Details

$db public property

This will use default db component from Yii application.
public string|Connection,yii\db $db
return string | yii\db\Connection

$hardDelete public property

Whether to do hard delete of the deleted job, instead of just flagging the status.
public bool $hardDelete
return boolean

$tableName public property

The table should be pre-created as follows for MySQL: php CREATE TABLE queue ( id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, status TINYINT NOT NULL DEFAULT 0, timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, data LONGBLOB );
public string $tableName
return string