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

View source

# 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

# channel

Type
string
Since
3.4.0

The channel column value to the queue should use.

View source

# commandClass

Type
string

Command class name

View source

# db

Type
craft\db\Connection, array, string
Since
3.4.0

The database connection to use

View source

# hasReservedJobs

Type
boolean
Access
Read-only

View source

# hasWaitingJobs

Type
boolean
Access
Read-only

View source

# jobInfo

Type
array
Access
Read-only

View source

# mutex

Type
yii\mutex\Mutex, array, string
Since
3.4.0

The mutex component to use

View source

# mutexTimeout

Type
integer

The time (in seconds) to wait for mutex locks to be released when attempting to reserve new jobs.

View source

# progress

Type
integer
Access
Write-only

The job progress (1-100)

View source

# tableName

Type
string
Since
3.4.0

The table name the queue is stored in.

View source

# totalDelayed

Type
integer
Access
Read-only

View source

# totalFailed

Type
integer
Access
Read-only

View source

# totalJobs

Type
integer, float
Access
Read-only
Since
3.4.0

View source

# totalReserved

Type
integer
Access
Read-only

View source

# totalWaiting

Type
integer
Access
Read-only

View source

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

View source

Returns

boolean

# getHasWaitingJobs()

Returns whether there are any waiting jobs.

View source

Returns

boolean

# 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

Arguments

Returns

array

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

Arguments

Returns

array

# getTotalDelayed()

Returns the total number of delayed jobs

View source

Returns

integer

# getTotalFailed()

Returns the total number of failed jobs

View source

Returns

integer

# getTotalJobs()

Since
3.4.0

Returns the total number of jobs in the queue.

View source

Returns

integer, float

# getTotalReserved()

Returns the total number of reserved jobs

View source

Returns

integer

# getTotalWaiting()

Returns the total number of waiting jobs

View source

Returns

integer

# handleError()

View source

Arguments

Returns

boolean

# handleResponse()

Figure out how to initiate a new worker.

View source

# 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

# isFailed()

View source

Arguments

Returns

boolean

# listen()

Listens to the queue and runs new jobs.

View source

Arguments

  • $delay (integer) – Number of seconds for waiting new job.

# push()

Pushes job into queue.

View source

Arguments

Returns

string, null – Id of a job message

# release()

Releases a job from the queue.

View source

Arguments

# releaseAll()

Since
3.4.0

Releases all jobs.

View source

# retry()

Re-adds a failed job to the queue.

View source

Arguments

# retryAll()

Since
3.4.0

Retries all failed jobs.

View source

# run()

Runs all the queued-up jobs.

View source

# setProgress()

Sets the progress for the currently reserved job.

View source

Arguments

# status()

View source

Arguments

  • $id

# Protected Methods

# pushMessage()

View source

Arguments

Returns

string – Id of a job message

# reserve()

View source

Returns

array, null – The payload, or null if there aren't any jobs to reserve

Throws

# Constants

Constant Description
STATUS_DONE
STATUS_FAILED
STATUS_RESERVED
STATUS_WAITING