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

Craft Queue

View source

Public Properties

PropertyDescription
attemptsinteger – Default attempt count
behaviorsyii\base\Behavior – List of behaviors attached to this component
commandClassstring – Command class name
commandOptionsarray – Of additional options of command
hasReservedJobsboolean
hasWaitingJobsboolean
jobInfoarray
loopConfigarray, string
mutexTimeoutinteger – Timeout
progressinteger – The job progress (1-100)
serializeryii\queue\serializers\SerializerInterface, array
strictJobTypeboolean – Whether to enable strict job type control.
totalDelayedinteger
totalFailedinteger
totalReservedinteger
totalWaitinginteger
ttrinteger – Default time to reserve a job
workerPid

commandClass

Type
string

Command class name

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

mutexTimeout

Type
integer

Timeout

View source

progress

Type
integer
Access
Write-only

The job progress (1-100)

View source

totalDelayed

Type
integer
Access
Read-only

View source

totalFailed

Type
integer
Access
Read-only

View source

totalReserved

Type
integer
Access
Read-only

View source

totalWaiting

Type
integer
Access
Read-only

View source

Public Methods

MethodDescription
__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
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
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.
retry()Re-adds a failed job to the queue.
retryAll()Re-adds all failed jobs to the queue
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.

getHasReservedJobs()

Returns whether there are any reserved jobs

View source

Returns

boolean

getHasWaitingJobs()

Returns whether there are any waiting jobs

View source

Returns

boolean

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

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

  • $id (string) – Of a job message

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

retry()

Re-adds a failed job to the queue.

View source

Arguments

retryAll()

Re-adds all failed jobs to the queue

View source

run()

Runs all the queued-up jobs

View source

setProgress()

Sets the progress for the currently reserved job.

View source

Arguments

  • $progress (integer) – The job progress (1-100)
  • $label (string, null) – The progress label

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

ConstantDescription
STATUS_DONE
STATUS_FAILED
STATUS_RESERVED
STATUS_WAITING