PHP Class UrbanIndo\Yii2\Queue\Queue

Since: 2015.02.24
Author: Petra Barus ([email protected])
Inheritance: extends yii\base\Component
Mostra file Open project: urbanindo/yii2-queue Class Usage Examples

Public Properties

Property Type Description
$module yii\base\Module To add the module, create a new module in the config e.g. create a module named 'task'. 'modules' => [ 'task' => [ 'class' => 'app\modules\task\Module', ] ] and then add the module to the queue config. 'components' => [ 'queue' => [ 'module' => 'task' ] ]
$releaseOnFailure boolean This will release automatically on execution failure. i.e. when the run method returns false or catch exception.
$serializer string Choose the serializer.

Public Methods

Method Description
delete ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Delete the job. This will trigger event EVENT_BEFORE_DELETE and EVENT_AFTER_DELETE.
fetch ( ) : UrbanIndo\Yii2\Queue\Job | boolean Return next job from the queue. This will trigger event EVENT_BEFORE_FETCH and event EVENT_AFTER_FETCH
getSize ( ) : integer Returns the number of queue size.
init ( ) : void Initializes the module.
post ( UrbanIndo\Yii2\Queue\Job &$job ) : boolean Post new job to the queue. This will trigger event EVENT_BEFORE_POST and EVENT_AFTER_POST.
purge ( ) : boolean Purge the whole queue.
release ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Release the job. This will trigger event EVENT_BEFORE_RELEASE and EVENT_AFTER_RELEASE.
run ( UrbanIndo\Yii2\Queue\Job $job ) : void Run the job.

Protected Methods

Method Description
deleteJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Delete the job. Override this for the queue implementation.
deserialize ( string $message ) : UrbanIndo\Yii2\Queue\Job Deserialize job to be executed.
deserializeMessage ( array $array ) : array
fetchJob ( ) : UrbanIndo\Yii2\Queue\Job | boolean Return next job from the queue. Override this for queue implementation.
postJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Post new job to the queue. Override this for queue implementation.
releaseJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean Release the job. Override this for the queue implementation.
serialize ( UrbanIndo\Yii2\Queue\Job $job ) : string Pack job so that it can be send.
serializeMessage ( mixed $array ) : array

Method Details

delete() public method

Delete the job. This will trigger event EVENT_BEFORE_DELETE and EVENT_AFTER_DELETE.
public delete ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job to delete.
return boolean whether the operation succeed.

deleteJob() abstract protected method

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

deserialize() protected method

Deserialize job to be executed.
protected deserialize ( string $message ) : UrbanIndo\Yii2\Queue\Job
$message string The json string.
return UrbanIndo\Yii2\Queue\Job The job.

deserializeMessage() protected method

protected deserializeMessage ( array $array ) : array
$array array The message to be deserialize.
return array

fetch() public method

Return next job from the queue. This will trigger event EVENT_BEFORE_FETCH and event EVENT_AFTER_FETCH
public fetch ( ) : UrbanIndo\Yii2\Queue\Job | boolean
return UrbanIndo\Yii2\Queue\Job | boolean the job or false if not found.

fetchJob() abstract protected method

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

getSize() abstract public method

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

init() public method

Initializes the module.
public init ( ) : void
return void

post() public method

Post new job to the queue. This will trigger event EVENT_BEFORE_POST and EVENT_AFTER_POST.
public post ( UrbanIndo\Yii2\Queue\Job &$job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job.
return boolean Whether operation succeed.

postJob() abstract protected method

Post new job to the queue. Override this for queue implementation.
abstract protected postJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job.
return boolean Whether operation succeed.

purge() abstract public method

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

release() public method

Release the job. This will trigger event EVENT_BEFORE_RELEASE and EVENT_AFTER_RELEASE.
public release ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job to delete.
return boolean whether the operation succeed.

releaseJob() abstract protected method

Release the job. Override this for the queue implementation.
abstract protected releaseJob ( UrbanIndo\Yii2\Queue\Job $job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job to release.
return boolean whether the operation succeed.

run() public method

Run the job.
public run ( UrbanIndo\Yii2\Queue\Job $job ) : void
$job UrbanIndo\Yii2\Queue\Job The job to be executed.
return void

serialize() protected method

Pack job so that it can be send.
protected serialize ( UrbanIndo\Yii2\Queue\Job $job ) : string
$job UrbanIndo\Yii2\Queue\Job The job to serialize.
return string JSON string.

serializeMessage() protected method

protected serializeMessage ( mixed $array ) : array
$array mixed Array to serialize.
return array

Property Details

$module public_oe property

To add the module, create a new module in the config e.g. create a module named 'task'. 'modules' => [ 'task' => [ 'class' => 'app\modules\task\Module', ] ] and then add the module to the queue config. 'components' => [ 'queue' => [ 'module' => 'task' ] ]
public Module,yii\base $module
return yii\base\Module

$releaseOnFailure public_oe property

This will release automatically on execution failure. i.e. when the run method returns false or catch exception.
public bool $releaseOnFailure
return boolean

$serializer public_oe property

Choose the serializer.
public string $serializer
return string