Queue
- Type
- Class
- Namespace
- craft\queue
- Inherits
- craft\queue\Queue » yii\queue\cli\Queue (opens new window) » yii\queue\Queue (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- craft\queue\QueueInterface, yii\base\BootstrapInterface (opens new window), yii\base\Configurable (opens new window)
- Since
- 3.0.0
Craft Queue
View source (opens new window)
# Public Properties
# channel
- Type
- string (opens new window)
- Default value
'queue'
- Since
- 3.4.0
The channel
column value to the queue should use.
View source (opens new window)
# commandClass
- Type
- string (opens new window)
- Default value
\craft\queue\Command::class
Command class name
View source (opens new window)
# db
- Type
- craft\db\Connection, array (opens new window), string (opens new window)
- Default value
'db'
- Since
- 3.4.0
The database connection to use
View source (opens new window)
# hasReservedJobs
- Type
- boolean (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# hasWaitingJobs
- Type
- boolean (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# jobInfo
- Type
- array (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# mutex
- Type
- yii\mutex\Mutex (opens new window), array (opens new window), string (opens new window)
- Default value
'mutex'
- Since
- 3.4.0
The mutex component to use
View source (opens new window)
# mutexTimeout
- Type
- integer (opens new window)
- Default value
5
The time (in seconds) to wait for mutex locks to be released when attempting to reserve new jobs.
View source (opens new window)
# progress
- Type
- integer (opens new window)
- Default value
null
- Access
- Write-only
The job progress (1-100)
View source (opens new window)
# tableName
- Type
- string (opens new window)
- Default value
\craft\db\Table::QUEUE
- Since
- 3.4.0
The table name the queue is stored in.
View source (opens new window)
# totalDelayed
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# totalFailed
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# totalJobs
- Type
- integer (opens new window), float (opens new window)
- Default value
null
- Access
- Read-only
- Since
- 3.4.0
View source (opens new window)
# totalReserved
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# totalWaiting
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
bootstrap() (opens new window) | Bootstrap method to be called during application bootstrap stage. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
delay() (opens new window) | Sets delay for later execute. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | 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() (opens new window) | Gets process ID of a worker. |
handleError() | |
handleResponse() | Figure out how to initiate a new worker. |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
isDone() (opens new window) | |
isFailed() | |
isReserved() (opens new window) | |
isWaiting() (opens new window) | |
listen() | Listens to the queue and runs new jobs. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
priority() (opens new window) | 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() (opens new window) | Triggers an event. |
ttr() (opens new window) | Sets TTR for job execute. |
unserializeMessage() (opens new window) | Unserializes. |
# getHasReservedJobs()
Returns whether there are any reserved jobs.
View source (opens new window)
Returns
# getHasWaitingJobs()
Returns whether there are any waiting jobs.
View source (opens new window)
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.
View source (opens new window)
Arguments
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
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)
View source (opens new window)
Arguments
Returns
# getTotalDelayed()
Returns the total number of delayed jobs
View source (opens new window)
Returns
# getTotalFailed()
Returns the total number of failed jobs
View source (opens new window)
Returns
# getTotalJobs()
- Since
- 3.4.0
Returns the total number of jobs in the queue.
View source (opens new window)
Returns
integer (opens new window), float (opens new window)
# getTotalReserved()
Returns the total number of reserved jobs
View source (opens new window)
Returns
# getTotalWaiting()
Returns the total number of waiting jobs
View source (opens new window)
Returns
# handleError()
View source (opens new window)
Arguments
$event
# handleResponse()
Figure out how to initiate a new worker.
View source (opens new window)
# init()
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
View source (opens new window)
# isFailed()
View source (opens new window)
Arguments
$id
(string (opens new window)) – Of a job message
Returns
# listen()
DEPRECATED
Deprecated in 3.6.11. Use run() instead.
Listens to the queue and runs new jobs.
View source (opens new window)
Arguments
$timeout
(integer (opens new window)) – The number of seconds to wait between cycles
# push()
Pushes job into queue.
View source (opens new window)
Arguments
$job
(yii\queue\JobInterface (opens new window),mixed
)
Returns
string (opens new window), null (opens new window) – Id of a job message
# release()
Releases a job from the queue.
View source (opens new window)
Arguments
# releaseAll()
- Since
- 3.4.0
Releases all jobs.
View source (opens new window)
# retry()
Re-adds a failed job to the queue.
View source (opens new window)
Arguments
# retryAll()
- Since
- 3.4.0
Retries all failed jobs.
View source (opens new window)
# run()
Runs all the queued-up jobs.
View source (opens new window)
Arguments
$repeat
(boolean (opens new window)) – Whether to continue listening when the queue is empty.$timeout
(integer (opens new window)) – The number of seconds to wait between cycles
# setProgress()
Sets the progress for the currently reserved job.
View source (opens new window)
Arguments
$progress
(integer (opens new window)) – The job progress (1-100)$label
(string (opens new window), null (opens new window)) – The progress label
# status()
View source (opens new window)
Arguments
$id
# Protected Methods
Method | Description |
---|---|
getCommandId() (opens new window) | |
handleMessage() (opens new window) | |
pushMessage() | |
reserve() | |
runWorker() (opens new window) | Runs worker. |
# pushMessage()
View source (opens new window)
Arguments
$message
(string (opens new window))$ttr
(integer (opens new window)) – Time to reserve in seconds$delay
(integer (opens new window))$priority
(mixed
)
Returns
string (opens new window) – Id of a job message
# reserve()
View source (opens new window)
Returns
array (opens new window), null (opens new window) – The payload, or null if there aren't any jobs to reserve
Throws
- yii\base\Exception (opens new window)
in case it hasn't waited the lock
# Constants
Constant | Description |
---|---|
STATUS_DONE | |
STATUS_FAILED | |
STATUS_RESERVED | |
STATUS_WAITING |