'queueName' => 'Name of the queue we will work with.',
];
/**
* The Command's Options
*
* @var array<string, string>
*/
protected$options = [
'-sleep' => 'Wait time between the next check for available job when the queue is empty. Default value: 10 (seconds).',
'-rest' => 'Rest time between the jobs in the queue. Default value: 0 (seconds)',
'-max-jobs' => 'The maximum number of jobs to handle before worker should exit. Disabled by default.',
'-max-time' => 'The maximum number of seconds worker should run. Disabled by default.',
'-memory' => 'The maximum memory in MB that worker can take. Default value: 128',
'-priority' => 'The priority for the jobs from the queue (comma separated). If not provided explicit, will follow the priorities defined in the config via $queuePriorities for the given queue. Disabled by default.',
'-tries' => 'The number of attempts after which the job will be considered as failed. Overrides settings from the Job class. Disabled by default.',
'-retry-after' => 'The number of seconds after which the job is to be restarted in case of failure. Overrides settings from the Job class. Disabled by default.',
'--stop-when-empty' => 'Stop when the queue is empty.',
];
/**
* Actually execute a command.
*
* @throws Exception
*/
publicfunctionrun(array$params)
{
set_time_limit(0);
/** @var QueueConfig $config */
$config = config('Queue');
$stopWhenEmpty = false;
$waiting = false;
// Read queue name from params
$queue = array_shift($params);
if ($queue === null) {
CLI::error('The queueName is not specified.');
returnEXIT_ERROR;
}
// Read options
[
$error,
$sleep,
$rest,
$maxJobs,
$maxTime,
$memory,
$priority,
$tries,
$retryAfter,
] = $this->readOptions($params, $config, $queue);
if ($error !== null) {
CLI::write($error, 'red');
returnEXIT_ERROR;
}
$countJobs = 0;
if (array_key_exists('stop-when-empty', $params) || CLI::getOption('stop-when-empty')) {