123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
-
- namespace Illuminate\Bus;
-
- trait Queueable
- {
- /**
- * The name of the connection the job should be sent to.
- *
- * @var string|null
- */
- public $connection;
-
- /**
- * The name of the queue the job should be sent to.
- *
- * @var string|null
- */
- public $queue;
-
- /**
- * The name of the connection the chain should be sent to.
- *
- * @var string|null
- */
- public $chainConnection;
-
- /**
- * The name of the queue the chain should be sent to.
- *
- * @var string|null
- */
- public $chainQueue;
-
- /**
- * The number of seconds before the job should be made available.
- *
- * @var \DateTimeInterface|\DateInterval|int|null
- */
- public $delay;
-
- /**
- * The jobs that should run if this job is successful.
- *
- * @var array
- */
- public $chained = [];
-
- /**
- * Set the desired connection for the job.
- *
- * @param string|null $connection
- * @return $this
- */
- public function onConnection($connection)
- {
- $this->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;
- }));
- }
- }
- }
|