connection = $connection; return $this; } /** * Set the desired queue for the job. * * @param string|null $queue * @return $this */ public function onQueue($queue) { $this->queue = $queue; return $this; } /** * Set the desired connection for the chain. * * @param string|null $connection * @return $this */ public function allOnConnection($connection) { $this->chainConnection = $connection; $this->connection = $connection; return $this; } /** * Set the desired queue for the chain. * * @param string|null $queue * @return $this */ public function allOnQueue($queue) { $this->chainQueue = $queue; $this->queue = $queue; return $this; } /** * Set the desired delay for the job. * * @param \DateTimeInterface|\DateInterval|int|null $delay * @return $this */ public function delay($delay) { $this->delay = $delay; return $this; } /** * Set the jobs that should run if this job is successful. * * @param array $chain * @return $this */ public function chain($chain) { $this->chained = collect($chain)->map(function ($job) { return serialize($job); })->all(); return $this; } /** * Dispatch the next job on the chain. * * @return void */ public function dispatchNextJobInChain() { if (! empty($this->chained)) { dispatch(tap(unserialize(array_shift($this->chained)), function ($next) { $next->chained = $this->chained; $next->onConnection($next->connection ?: $this->chainConnection); $next->onQueue($next->queue ?: $this->chainQueue); $next->chainConnection = $this->chainConnection; $next->chainQueue = $this->chainQueue; })); } } }