Skip to content

Command

Type
Class
Namespace
craft\queue
Inherits
craft\queue\Command » yii\queue\cli\Command » yii\console\Controller » yii\base\Controller » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable, yii\base\ViewContextInterface
Uses traits
craft\console\ControllerTrait
Since
3.0.0

Manages the queue.

View source

Public Properties

PropertyDescription
actionyii\base\Action, null – The action that is currently being executed.
behaviorsyii\base\Behavior – List of behaviors attached to this component.
colorboolean, null – Whether to enable ANSI color in the output.
defaultActionstring
helpboolean – Whether to display help information about current command.
helpSummarystring
idstring – The ID of this controller.
interactiveboolean – Whether to run the command interactively.
isolateboolean – Isolate mode.
isolated– Whether the command should ensure it is only being run once at a time.
jobIdstring – The job ID to run
layoutstring, null, false – The name of the layout to be applied to this controller's views.
moduleyii\base\Module – The module that this controller belongs to.
modulesyii\base\Module – All ancestor modules that this controller is located within.
passedOptionValuesarray – The properties corresponding to the passed options.
passedOptionsarray – The names of the options passed during execution.
phpBinarystring – Path to php interpreter that uses to run child processes.
queuecraft\queue\Queue
requestyii\base\Request, array, string – The request.
responseyii\base\Response, array, string – The response.
routestring – The route (module ID, controller ID and action ID) of the current request.
silentExitOnExceptionboolean, null – If true - script finish with ExitCode::OK in case of exception.
uniqueIdstring – The controller ID that is prefixed with the module ID (if any).
verboseboolean – Verbose mode of a job execute.
verboseConfigarray – Additional options to the verbose behavior.
viewyii\base\View, yii\web\View – The view object that can be used to render views or view files.
viewPathstring – The directory containing the view files for this controller.

defaultAction

Type
string
Default value
'info'

View source

jobId

Type
string
Default value
null
Since
4.8.0

The job ID to run

View source

queue

Type
craft\queue\Queue
Default value
null

View source

verboseConfig

Type
array
Default value
[ 'class' => \craft\queue\VerboseBehavior::class, ]

Additional options to the verbose behavior.

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()
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
actionListen()Listens for new jobs added to the queue and runs them.
actionRelease()Releases job(s) from the queue.
actionRetry()Re-adds a failed job(s) to the queue.
actionRun()Runs all jobs in the queue.
actions()Declares external actions for the controller.
afterAction()This method is invoked right after an action is executed.
ansiFormat()Formats a string with ANSI codes.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
beforeAction()This method is invoked right before an action is executed.
behaviors()Returns a list of behaviors that this component should behave as.
bindActionParams()Binds the parameters to the action.
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.
confirm()Asks user to confirm by typing y or n.
createAction()Creates an action based on the given action ID.
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.
failure()Outputs a failure message to the console.
findLayoutFile()Finds the applicable layout file.
getActionArgsHelp()Returns the help information for the anonymous arguments for the action.
getActionHelp()Returns the detailed help information for the specified action.
getActionHelpSummary()Returns a one-line short summary describing the specified action.
getActionOptionsHelp()Returns the help information for the options for the action.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getHelp()Returns help information for this controller.
getHelpSummary()Returns one-line short summary describing this controller.
getModules()Returns all ancestor modules of this controller.
getOptionValues()Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties.
getPassedOptionValues()Returns the properties corresponding to the passed options.
getPassedOptions()Returns the names of valid options passed during execution.
getRoute()Returns the route of the current request.
getUniqueId()Returns the unique ID of the controller.
getView()Returns the view object that can be used to render views or view files.
getViewPath()Returns the directory containing view files for this controller.
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 for this component.
init()Initializes the object.
isColorEnabled()Returns a value indicating whether ANSI color is enabled.
markdownToAnsi()Converts Markdown to be better readable in console environments by applying some ANSI format.
note()Outputs a note to the console.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
optionAliases()Returns option alias names.
options()Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.
prompt()Prompts the user for input and validates it.
render()Renders a view and applies layout if available.
renderContent()Renders a static string by applying a layout.
renderFile()Renders a view file.
renderPartial()Renders a view without applying layout.
run()Runs a request specified in terms of a route.
runAction()Runs an action within this controller with the specified action ID and parameters.
select()Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
setView()Sets the view object to be used by this controller.
setViewPath()Sets the directory that contains the view files.
stderr()Prints a string to STDERR.
stdout()Prints a string to STDOUT.
success()Outputs a success message to the console.
tip()Outputs a tip to the console.
trigger()Triggers an event.
warning()Outputs a warning to the console.

actionListen()

Listens for new jobs added to the queue and runs them.

View source

Arguments

  • $timeout (integer) – The number of seconds to wait between cycles.

Returns

integer

actionRelease()

Since
3.4.0

Releases job(s) from the queue.

Example:

php craft queue/release all

View source

Arguments

  • $job (string) – The job ID to release. Pass all to release all jobs.

Returns

integer

Throws

actionRetry()

Since
3.1.21

Re-adds a failed job(s) to the queue.

View source

Arguments

  • $job (integer, string) – The job ID that should be retried, or all to retry all failed jobs.

Returns

integer

actionRun()

Runs all jobs in the queue.

View source

Returns

integer

actions()

Declares external actions for the controller.

This method is meant to be overwritten to declare external actions for the controller. It should return an array, with array keys being action IDs, and array values the corresponding action class names or action configuration arrays. For example,

php
return [
    'action1' => 'app\components\Action1',
    'action2' => [
        'class' => 'app\components\Action2',
        'property1' => 'value1',
        'property2' => 'value2',
    ],
];

\Yii::createObject() will be used later to create the requested action using the configuration provided here.

View source

Returns

array

options()

Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.

Child classes may override this method to specify possible options.

Note that the values setting via options are not available until beforeAction() is being called.

View source

Arguments

  • $actionID (string) – The action id of the current request

Returns

string[] – The names of the options valid for the action

Protected Methods

MethodDescription
bindInjectedParams()Fills parameters based on types and names in action method signature.
canIsolate()
canVerbose()
checkRootUser()Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that.
checkTty()Sets yii\console\Controller::$interactive to false if this isn’t a TTY shell.
createAttributeValidator()Creates a function for the validator option of Controller::prompt.
getActionMethodReflection()
handleMessage()Handles message using child process.
isWorkerAction()
outputCommand()
parseDocCommentDetail()Returns full description from the docblock.
parseDocCommentSummary()Returns the first line of docblock.
parseDocCommentTags()Parses the comment block into tags.

isWorkerAction()

View source

Arguments

Returns

boolean

Constants

ConstantDescription
EXEC_DONEThe exit code of the exec action which is returned when job was done.
EXEC_RETRYThe exit code of the exec action which is returned when job wasn't done and wanted next attempt.
EXIT_CODE_ERROR
EXIT_CODE_NORMAL