Queue ​
- Type
- Class
- Namespace
- craft\queue
- Inherits
- craft\queue\Queue » yii\queue\cli\Queue » yii\queue\Queue » yii\base\Component » yii\base\BaseObject
- Implements
- craft\queue\QueueInterface, yii\base\BootstrapInterface, yii\base\Configurable
- Since
- 3.0.0
Craft Queue
Public Properties ​
| Property | Description |
|---|---|
| attempts | integer – Default attempt count |
| behaviors | yii\base\Behavior – List of behaviors attached to this component. |
| channel | string – The channel column value to the queue should use. |
| commandClass | string – Command class name |
| commandOptions | array – Of additional options of command |
| db | craft\db\Connection, array, string – The database connection to use |
| hasReservedJobs | boolean |
| hasWaitingJobs | boolean |
| jobInfo | array |
| loopConfig | array, string |
| mutex | yii\mutex\Mutex, array, string – The mutex component to use |
| mutexTimeout | integer – The time (in seconds) to wait for mutex locks to be released when attempting to reserve new jobs. |
| progress | integer – The job progress (1-100) |
| serializer | yii\queue\serializers\SerializerInterface, array |
| strictJobType | boolean – Whether to enable strict job type control. |
| tableName | string – The table name the queue is stored in. |
| totalDelayed | integer |
| totalFailed | integer |
| totalJobs | integer, float |
| totalReserved | integer |
| totalWaiting | integer |
| ttr | integer – Default time to reserve a job |
| workerPid | null, integer |
channel ​
- Type
- string
- Default value
'queue'- Since
- 3.4.0
The channel column value to the queue should use.
commandClass ​
- Type
- string
- Default value
\craft\queue\Command::class
Command class name
db ​
- Type
- craft\db\Connection, array, string
- Default value
'db'- Since
- 3.4.0
The database connection to use
hasReservedJobs ​
- Type
- boolean
- Default value
null- Access
- Read-only
hasWaitingJobs ​
- Type
- boolean
- Default value
null- Access
- Read-only
jobInfo ​
- Type
- array
- Default value
null- Access
- Read-only
mutex ​
- Type
- yii\mutex\Mutex, array, string
- Default value
'mutex'- Since
- 3.4.0
The mutex component to use
mutexTimeout ​
- Type
- integer
- Default value
5
The time (in seconds) to wait for mutex locks to be released when attempting to reserve new jobs.
progress ​
- Type
- integer
- Default value
null- Access
- Write-only
The job progress (1-100)
tableName ​
- Type
- string
- Default value
\craft\db\Table::QUEUE- Since
- 3.4.0
The table name the queue is stored in.
totalDelayed ​
- Type
- integer
- Default value
null- Access
- Read-only
totalFailed ​
- Type
- integer
- Default value
null- Access
- Read-only
totalJobs ​
totalReserved ​
- Type
- integer
- Default value
null- Access
- Read-only
totalWaiting ​
- Type
- integer
- Default value
null- Access
- Read-only
Public Methods ​
| Method | Description |
|---|---|
| __call() | Calls the named method which is not a class method. |
| __clone() | This method is called after the object is created by cloning an existing one. |
| __construct() | Constructor. |
| __get() | Returns the value of a component property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __set() | Sets the value of a component property. |
| __unset() | Sets a component property to be null. |
| attachBehavior() | Attaches a behavior to this component. |
| attachBehaviors() | Attaches a list of behaviors to the component. |
| behaviors() | Returns a list of behaviors that this component should behave as. |
| bootstrap() | Bootstrap method to be called during application bootstrap stage. |
| canGetProperty() | Returns a value indicating whether a property can be read. |
| canSetProperty() | Returns a value indicating whether a property can be set. |
| className() | Returns the fully qualified name of this class. |
| delay() | Sets delay for later execute. |
| detachBehavior() | Detaches a behavior from the component. |
| detachBehaviors() | Detaches all behaviors from the component. |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
| getBehavior() | Returns the named behavior object. |
| getBehaviors() | Returns all behaviors attached to this component. |
| getHasReservedJobs() | Returns whether there are any reserved jobs. |
| getHasWaitingJobs() | Returns whether there are any waiting jobs. |
| getJobDetails() | Returns detailed info about a single job. |
| getJobInfo() | Returns info about the jobs in the queue. |
| getTotalDelayed() | Returns the total number of delayed jobs |
| getTotalFailed() | Returns the total number of failed jobs |
| getTotalJobs() | Returns the total number of jobs in the queue. |
| getTotalReserved() | Returns the total number of reserved jobs |
| getTotalWaiting() | Returns the total number of waiting jobs |
| getWorkerPid() | Gets process ID of a worker. |
| handleError() | |
| handleResponse() | Figure out how to initiate a new worker. |
| hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
| hasMethod() | Returns a value indicating whether a method is defined. |
| hasProperty() | Returns a value indicating whether a property is defined for this component. |
| init() | Initializes the object. |
| isDone() | |
| isFailed() | |
| isReserved() | |
| isWaiting() | |
| listen() | Listens to the queue and runs new jobs. |
| off() | Detaches an existing event handler from this component. |
| on() | Attaches an event handler to an event. |
| priority() | Sets job priority. |
| push() | Pushes job into queue. |
| release() | Releases a job from the queue. |
| releaseAll() | Releases all jobs. |
| retry() | Re-adds a failed job to the queue. |
| retryAll() | Retries all failed jobs. |
| run() | Runs all the queued-up jobs. |
| setProgress() | Sets the progress for the currently reserved job. |
| status() | |
| trigger() | Triggers an event. |
| ttr() | Sets TTR for job execute. |
| unserializeMessage() | Unserializes. |
getHasReservedJobs() ​
Returns whether there are any reserved jobs.
Returns ​
getHasWaitingJobs() ​
Returns whether there are any waiting jobs.
Returns ​
getJobDetails() ​
- Since
- 3.4.0
Returns detailed info about a single job.
The response array can contain the following keys:
delay– the number of seconds remaining before the job will startstatus– the job status (1 = waiting, 2 = reserved, 3 = done, 4 = failed)progress– the job progress (0-100)description– the job descriptionttr– the job’s time-to-reserve, in secondserror– the error message (if the job failed)job– the deserialized job
Any other key/value pairs are allowed and will be displayed on the details page.
Arguments ​
$id(string)
Returns ​
Throws ​
- yii\base\InvalidArgumentException
if $id is an invalid job ID
getJobInfo() ​
Returns info about the jobs in the queue.
The response array should have sub-arrays with the following keys:
id– the job IDdelay– the number of seconds remaining before the job will startstatus– the job status (1 = waiting, 2 = reserved, 3 = done, 4 = failed)progress– the job progress (0-100)description– the job descriptionerror– the error message (if the job failed)
Arguments ​
Returns ​
getTotalDelayed() ​
Returns the total number of delayed jobs
Returns ​
getTotalFailed() ​
Returns the total number of failed jobs
Returns ​
getTotalJobs() ​
- Since
- 3.4.0
Returns the total number of jobs in the queue.
Returns ​
getTotalReserved() ​
Returns the total number of reserved jobs
Returns ​
getTotalWaiting() ​
Returns the total number of waiting jobs
Returns ​
handleError() ​
Arguments ​
$event
handleResponse() ​
Figure out how to initiate a new worker.
init() ​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
isFailed() ​
Arguments ​
$id(string) – Of a job message
Returns ​
listen() ​
DEPRECATED
Deprecated in 3.6.11. Use run() instead.
Listens to the queue and runs new jobs.
Arguments ​
$timeout(integer) – The number of seconds to wait between cycles
push() ​
Pushes job into queue.
Arguments ​
$job(yii\queue\JobInterface,mixed)
Returns ​
string, null – Id of a job message
release() ​
Releases a job from the queue.
Arguments ​
$id(string)
releaseAll() ​
- Since
- 3.4.0
Releases all jobs.
retry() ​
Re-adds a failed job to the queue.
Arguments ​
$id(string)
retryAll() ​
- Since
- 3.4.0
Retries all failed jobs.
run() ​
Runs all the queued-up jobs.
Arguments ​
$repeat(boolean) – Whether to continue listening when the queue is empty.$timeout(integer) – The number of seconds to wait between cycles
setProgress() ​
Sets the progress for the currently reserved job.
Arguments ​
status() ​
Arguments ​
$id
Protected Methods ​
| Method | Description |
|---|---|
| getCommandId() | |
| handleMessage() | |
| pushMessage() | |
| reserve() | |
| runWorker() | Runs worker. |
pushMessage() ​
Arguments ​
Returns ​
string – Id of a job message
reserve() ​
Returns ​
array, null – The payload, or null if there aren't any jobs to reserve
Throws ​
- yii\base\Exception
in case it hasn't waited the lock
Constants ​
| Constant | Description |
|---|---|
STATUS_DONE | |
STATUS_FAILED | |
STATUS_RESERVED | |
STATUS_WAITING |