each( fn ($value, $option) => method_exists($self, 'set' . ucfirst($option)) ? $self->{'set' . ucfirst($option)}($value) : throw new Exception(sprintf('Unknown option "%s"', $option)) ); return $self; } /** * Get the worker options * */ public function getWorkerOptions(): array { return [ 'name' => $this->getName(), 'backoff' => $this->getBackoff(), 'memory' => $this->getMemory(), 'timeout' => $this->getTimeout(), 'sleep' => $this->getSleep(), 'maxTries' => $this->getMaxTries(), 'force' => $this->getForce(), 'stopWhenEmpty' => $this->getStopWhenEmpty(), 'maxJobs' => $this->getMaxJobs(), 'maxTime' => $this->getMaxTime(), 'rest' => $this->getRest(), ]; } /** * Set the worker name */ public function setName(string $name): self { $this->name = $name; return $this; } /** * Get the worker name */ public function getName(): string { return $this->name; } /** * The number of seconds to wait before retrying the job */ public function setBackoff(int $value): self { $this->backoff = $value; return $this; } /** * Get the number of seconds to wait before retrying the job */ public function getBackoff(): int { return $this->backoff; } /** * The maximum amount of RAM(in megabytes) the worker may consume. */ public function setMemory(int $value): self { $this->memory = $value; return $this; } /** * Get Job's allowed memory value(in megabytes) */ public function getMemory(): int { return $this->memory; } /** * The maximum number of seconds a child worker may run. */ public function setTimeout(int $value): self { $this->timeout = $value; return $this; } /** * Get Job's timeout value */ public function getTimeout(): int { return $this->timeout; } /** * The number of seconds to wait in between polling the queue. */ public function setSleep(int $value): self { $this->sleep = $value; return $this; } /** * Get Job's sleep value */ public function getSleep(): int { return $this->sleep; } /** * Set the Job's max attempts */ public function setMaxTries(int $maxTries): self { $this->maxTries = $maxTries; return $this; } /** * Get the Job's max attempts */ public function getMaxTries(): int { return $this->maxTries; } /** * Indicates if the worker should run in maintenance mode. */ public function setForce(bool $value = false): self { $this->force = $value; return $this; } /** * Get Job's force flag value */ public function getForce(): bool { return $this->force; } /** * Indicates if the worker should stop when queue is empty. */ public function setStopWhenEmpty(bool $value = false): self { $this->stopWhenEmpty = $value; return $this; } /** * Get Job's stop when empty settings value */ public function getStopWhenEmpty(): bool { return $this->stopWhenEmpty; } /** * Set max number of jobs to process before stopping */ public function setMaxJobs(int $maxJobs): self { $this->maxJobs = $maxJobs; return $this; } /** * Get max number of jobs to process before stopping */ public function getMaxJobs(): int { return $this->maxJobs; } /** * Set maximum number of seconds the worker should run */ public function setMaxTime(int $maxTime): self { $this->maxTime = $maxTime; return $this; } /** * Get maximum number of seconds the worker should run */ public function getMaxTime(): int { return $this->maxTime; } /** * Set number of seconds to rest between jobs */ public function setRest(int $rest): self { $this->rest = $rest; return $this; } /** * Get number of seconds to rest between jobs */ public function getRest(): int { return $this->rest; } }