master

laravel/framework

Last updated at: 29/12/2023 09:24

WorkerOptions.php

TLDR

The WorkerOptions class in the Illuminate\Queue namespace is used to configure the options for a worker in a queue system.

Classes

WorkerOptions

The WorkerOptions class is responsible for holding the configuration options for a worker in the queue system. It has the following properties:

  • name (string): The name of the worker.
  • backoff (int|int[]): The number of seconds to wait before retrying a job that encountered an uncaught exception.
  • memory (int): The maximum amount of RAM the worker may consume.
  • timeout (int): The maximum number of seconds a child worker may run.
  • sleep (int): The number of seconds to wait in between polling the queue.
  • rest (int): The number of seconds to rest between jobs.
  • maxTries (int): The maximum number of times a job may be attempted.
  • force (bool): Indicates if the worker should run in maintenance mode.
  • stopWhenEmpty (bool): Indicates if the worker should stop when the queue is empty.
  • maxJobs (int): The maximum number of jobs to run.
  • maxTime (int): The maximum number of seconds a worker may live.

The WorkerOptions class has a constructor that accepts the above properties. Each property has a default value assigned to it.

<?php

namespace Illuminate\Queue;

class WorkerOptions
{
    /**
     * The name of the worker.
     *
     * @var string
     */
    public $name;

    /**
     * The number of seconds to wait before retrying a job that encountered an uncaught exception.
     *
     * @var int|int[]
     */
    public $backoff;

    /**
     * The maximum amount of RAM the worker may consume.
     *
     * @var int
     */
    public $memory;

    /**
     * The maximum number of seconds a child worker may run.
     *
     * @var int
     */
    public $timeout;

    /**
     * The number of seconds to wait in between polling the queue.
     *
     * @var int
     */
    public $sleep;

    /**
     * The number of seconds to rest between jobs.
     *
     * @var int
     */
    public $rest;

    /**
     * The maximum number of times a job may be attempted.
     *
     * @var int
     */
    public $maxTries;

    /**
     * Indicates if the worker should run in maintenance mode.
     *
     * @var bool
     */
    public $force;

    /**
     * Indicates if the worker should stop when the queue is empty.
     *
     * @var bool
     */
    public $stopWhenEmpty;

    /**
     * The maximum number of jobs to run.
     *
     * @var int
     */
    public $maxJobs;

    /**
     * The maximum number of seconds a worker may live.
     *
     * @var int
     */
    public $maxTime;

    /**
     * Create a new worker options instance.
     *
     * @param  string  $name
     * @param  int|int[]  $backoff
     * @param  int  $memory
     * @param  int  $timeout
     * @param  int  $sleep
     * @param  int  $maxTries
     * @param  bool  $force
     * @param  bool  $stopWhenEmpty
     * @param  int  $maxJobs
     * @param  int  $maxTime
     * @param  int  $rest
     * @return void
     */
    public function __construct($name = 'default', $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1,
                                $force = false, $stopWhenEmpty = false, $maxJobs = 0, $maxTime = 0, $rest = 0)
    {
        $this->name = $name;
        $this->backoff = $backoff;
        $this->sleep = $sleep;
        $this->rest = $rest;
        $this->force = $force;
        $this->memory = $memory;
        $this->timeout = $timeout;
        $this->maxTries = $maxTries;
        $this->stopWhenEmpty = $stopWhenEmpty;
        $this->maxJobs = $maxJobs;
        $this->maxTime = $maxTime;
    }
}