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
$messageHandlercallable, null
$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

Signature

public string $commandClass = \craft\queue\Command::class

$hasReservedJobs

Type
boolean
Access
Read-only

View source

Signature

public boolean getHasReservedJobs ( )

$hasWaitingJobs

Type
boolean
Access
Read-only

View source

Signature

public boolean getHasWaitingJobs ( )

$jobInfo

Type
array
Access
Read-only

View source

Signature

public array getJobInfo ( \craft\queue\int $limit = null )

$mutexTimeout

Signature

public integer $mutexTimeout = 3

$progress

Type
integer
Access
Write-only

The job progress (1-100)

View source

Signature

public void setProgress ( \craft\queue\int $progress )

$totalDelayed

Type
integer
Access
Read-only

View source

Signature

public integer getTotalDelayed ( )

$totalFailed

Type
integer
Access
Read-only

View source

Signature

public integer getTotalFailed ( )

$totalReserved

Type
integer
Access
Read-only

View source

Signature

public integer getTotalReserved ( )

$totalWaiting

Type
integer
Access
Read-only

View source

Signature

public integer getTotalWaiting ( )

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.
execute()
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.
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

Signature

public boolean getHasReservedJobs ( )

getHasWaitingJobs()

Returns whether there are any waiting jobs

View source

Returns

boolean

Signature

public boolean getHasWaitingJobs ( )

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

Signature

public array getJobInfo ( \craft\queue\int $limit = null )

getTotalDelayed()

Returns the total number of delayed jobs

View source

Returns

integer

Signature

public integer getTotalDelayed ( )

getTotalFailed()

Returns the total number of failed jobs

View source

Returns

integer

Signature

public integer getTotalFailed ( )

getTotalReserved()

Returns the total number of reserved jobs

View source

Returns

integer

Signature

public integer getTotalReserved ( )

getTotalWaiting()

Returns the total number of waiting jobs

View source

Returns

integer

Signature

public integer getTotalWaiting ( )

handleError()

View source

Arguments

Returns

boolean

Signature

public boolean handleError ( $id, $job, $ttr, $attempt, $error )

handleResponse()

Figure out how to initiate a new worker.

View source

Signature

public void handleResponse ( )

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

Signature

public void init ( )

isFailed()

View source

Arguments

  • $id (string) – Of a job message

Returns

boolean

Signature

public boolean isFailed ( \craft\queue\string $id )

listen()

Listens to the queue and runs new jobs.

View source

Arguments

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

Signature

public void listen ( \craft\queue\int $delay )

push()

Pushes job into queue.

View source

Arguments

Returns

string, null – Id of a job message

Signature

public string, null push ( $job )

release()

Releases a job from the queue.

View source

Arguments

Signature

public void release ( \craft\queue\string $id )

retry()

Re-adds a failed job to the queue.

View source

Arguments

Signature

public void retry ( \craft\queue\string $id )

run()

Runs all the queued-up jobs

View source

Signature

public void run ( )

setProgress()

Sets the progress for the currently reserved job.

View source

Arguments

  • $progress (integer) – The job progress (1-100)

Signature

public void setProgress ( \craft\queue\int $progress )

status()

View source

Arguments

  • $id

Signature

public void status ( $id )

Protected Methods

pushMessage()

View source

Arguments

Returns

string – Id of a job message

Signature

protected string pushMessage ( $message, $ttr, $delay, $priority )

reserve()

View source

Returns

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

Throws

Signature

protected array, null reserve ( )

Constants

ConstantDescription
STATUS_DONE
STATUS_FAILED
STATUS_RESERVED
STATUS_WAITING