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

Property Description
attempts (opens new window) integer (opens new window) – Default attempt count
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component
channel string (opens new window) – The channel column value to the queue should use.
commandClass string (opens new window) – Command class name
commandOptions (opens new window) array (opens new window) – Of additional options of command
db craft\db\Connection, array (opens new window), string (opens new window) – The database connection to use
hasReservedJobs boolean (opens new window)
hasWaitingJobs boolean (opens new window)
jobInfo array (opens new window)
loopConfig (opens new window) array (opens new window), string (opens new window)
mutex yii\mutex\Mutex (opens new window), array (opens new window), string (opens new window) – The mutex component to use
mutexTimeout integer (opens new window) – The time (in seconds) to wait for mutex locks to be released when attempting to reserve new jobs.
progress integer (opens new window) – The job progress (1-100)
serializer (opens new window) yii\queue\serializers\SerializerInterface (opens new window), array (opens new window)
strictJobType (opens new window) boolean (opens new window) – Whether to enable strict job type control.
tableName string (opens new window) – The table name the queue is stored in.
totalDelayed integer (opens new window)
totalFailed integer (opens new window)
totalJobs integer (opens new window), float (opens new window)
totalReserved integer (opens new window)
totalWaiting integer (opens new window)
ttr (opens new window) integer (opens new window) – Default time to reserve a job
workerPid (opens new window)

# 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
3

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 an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__unset() (opens new window) Sets an object property to 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) Uses for CLI drivers and 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.
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

boolean (opens new window)

# getHasWaitingJobs()

Returns whether there are any waiting jobs.

View source (opens new window)

Returns

boolean (opens new window)

# getJobDetails()

Since
3.4.0

Returns detailed info about a single job.

The response array can contain the following keys:

  • status – the job status (1 = waiting, 2 = reserved, 3 = done, 4 = failed)
  • progress – the job progress (0-100)
  • description – the job description
  • ttr – the job’s time-to-reserve, in seconds
  • error – 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

array (opens new window)

Throws

# getJobInfo()

Returns info about the jobs in the queue.

The response array should have sub-arrays with the following keys:

  • id – the job ID
  • status – the job status (1 = waiting, 2 = reserved, 3 = done, 4 = failed)
  • progress – the job progress (0-100)
  • description – the job description
  • error – the error message (if the job failed)

View source (opens new window)

Arguments

Returns

array (opens new window)

# getTotalDelayed()

Returns the total number of delayed jobs

View source (opens new window)

Returns

integer (opens new window)

# getTotalFailed()

Returns the total number of failed jobs

View source (opens new window)

Returns

integer (opens new window)

# 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

integer (opens new window)

# getTotalWaiting()

Returns the total number of waiting jobs

View source (opens new window)

Returns

integer (opens new window)

# handleError()

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# 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

Returns

boolean (opens new window)

# listen()

Listens to the queue and runs new jobs.

View source (opens new window)

Arguments

# push()

Pushes job into queue.

View source (opens new window)

Arguments

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)

# setProgress()

Sets the progress for the currently reserved job.

View source (opens new window)

Arguments

# status()

View source (opens new window)

Arguments

  • $id

# Protected Methods

# pushMessage()

View source (opens new window)

Arguments

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

# Constants

Constant Description
STATUS_DONE
STATUS_FAILED
STATUS_RESERVED
STATUS_WAITING