name = $name; $this->nice = $nice; $this->balance = $balance; $this->connection = $connection; $this->maxProcesses = $maxProcesses; $this->minProcesses = $minProcesses; $this->queue = $queue ?: config('queue.connections.'.$connection.'.queue'); parent::__construct($delay, $memory, $timeout, $sleep, $maxTries, $force); } /** * Create a fresh options instance with the given queue. * * @param string $queue * @return static */ public function withQueue($queue) { return tap(clone $this, function ($options) use ($queue) { $options->queue = $queue; }); } /** * Determine if a balancing strategy should be used. * * @return bool */ public function balancing() { return in_array($this->balance, ['simple', 'auto']); } /** * Determine if auto-scaling should be applied. * * @return bool */ public function autoScaling() { return $this->balance === 'auto'; } /** * Get the command-line representation of the options for a supervisor. * * @return string */ public function toSupervisorCommand() { return SupervisorCommandString::fromOptions($this); } /** * Get the command-line representation of the options for a worker. * * @return string */ public function toWorkerCommand() { return WorkerCommandString::fromOptions($this); } /** * Convert the options to a JSON string. * * @return string */ public function toJson() { return json_encode($this->toArray()); } /** * Convert the options to a raw array. * * @return array */ public function toArray() { return [ 'balance' => $this->balance, 'connection' => $this->connection, 'queue' => $this->queue, 'delay' => $this->delay, 'force' => $this->force, 'maxProcesses' => $this->maxProcesses, 'minProcesses' => $this->minProcesses, 'maxTries' => $this->maxTries, 'memory' => $this->memory, 'nice' => $this->nice, 'name' => $this->name, 'sleep' => $this->sleep, 'timeout' => $this->timeout, ]; } /** * Create a new options instance from the given array. * * @param array $array * @return static */ public static function fromArray(array $array) { return tap(new static($array['name'], $array['connection']), function ($options) use ($array) { foreach ($array as $key => $value) { $options->{$key} = $value; } }); } }