closure = $closure; } /** * Set the desired connection for the job. * * @param \UnitEnum|string|null $connection * @return $this */ public function onConnection($connection) { $this->connection = enum_value($connection); return $this; } /** * Set the desired queue for the job. * * @param \UnitEnum|string|null $queue * @return $this */ public function onQueue($queue) { $this->queue = enum_value($queue); return $this; } /** * Set the desired job "group". * * This feature is only supported by some queues, such as Amazon SQS. * * @param \UnitEnum|string $group * @return $this */ public function onGroup($group) { $this->messageGroup = enum_value($group); return $this; } /** * Set the desired job deduplicator callback. * * This feature is only supported by some queues, such as Amazon SQS FIFO. * * @param callable|null $deduplicator * @return $this */ public function withDeduplicator($deduplicator) { $this->deduplicator = $deduplicator instanceof Closure ? new SerializableClosure($deduplicator) : $deduplicator; return $this; } /** * Set the desired delay in seconds for the job. * * @param \DateTimeInterface|\DateInterval|int|null $delay * @return $this */ public function delay($delay) { $this->delay = $delay; return $this; } /** * Specify a callback that should be invoked if the queued listener job fails. * * @param \Closure $closure * @return $this */ public function catch(Closure $closure) { $this->catchCallbacks[] = $closure; return $this; } /** * Resolve the actual event listener callback. * * @return \Closure */ public function resolve() { return function (...$arguments) { dispatch(new CallQueuedListener(InvokeQueuedClosure::class, 'handle', [ 'closure' => new SerializableClosure($this->closure), 'arguments' => $arguments, 'catch' => (new Collection($this->catchCallbacks)) ->map(fn ($callback) => new SerializableClosure($callback)) ->all(), ])) ->onConnection($this->connection) ->onQueue($this->queue) ->delay($this->delay) ->onGroup($this->messageGroup) ->withDeduplicator($this->deduplicator); }; } }