From 1a3b37a84638d433ca44a7157a7aedeb5eb76929 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 10:04:24 -0500 Subject: [PATCH 01/12] prototype failover queue --- src/Illuminate/Bus/Dispatcher.php | 36 ++++++++++++++++++++++++--- src/Illuminate/Queue/Queue.php | 30 ++++++++++++++++++++++ src/Illuminate/Queue/QueueManager.php | 8 +++++- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 01bf5ec457d7..198cfb06f2e9 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -5,6 +5,7 @@ use Closure; use Illuminate\Contracts\Bus\QueueingDispatcher; use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\PendingChain; @@ -13,6 +14,7 @@ use Illuminate\Queue\Jobs\SyncJob; use Illuminate\Support\Collection; use RuntimeException; +use Throwable; class Dispatcher implements QueueingDispatcher { @@ -227,11 +229,37 @@ public function dispatchToQueue($command) throw new RuntimeException('Queue resolver did not return a Queue implementation.'); } - if (method_exists($command, 'queue')) { - return $command->queue($queue, $command); - } + try { + if (method_exists($command, 'queue')) { + return $command->queue($queue, $command); + } + + return $this->pushCommandToQueue($queue, $command); + } catch (Throwable $e) { + if (empty($queue->getConfig()['failover'] ?? [])) { + throw $e; + } + + $exceptionHandler = $this->container->bound(ExceptionHandler::class) + ? $this->container->make(ExceptionHandler::class) + : null; + + $exceptionHandler?->report($e); - return $this->pushCommandToQueue($queue, $command); + foreach ((array) ($queue->getConfig()['failover'] ?? []) as $failover) { + try { + $command->connection = $failover; + + return $this->dispatchToQueue($command); + } catch (Throwable $failoverException) { + // + } + } + + if (isset($failoverException)) { + throw $failoverException; + } + } } /** diff --git a/src/Illuminate/Queue/Queue.php b/src/Illuminate/Queue/Queue.php index 15a1edd587a6..ecf4ac3fdd8a 100755 --- a/src/Illuminate/Queue/Queue.php +++ b/src/Illuminate/Queue/Queue.php @@ -38,6 +38,13 @@ abstract class Queue */ protected $connectionName; + /** + * The original configuration for the queue. + * + * @var array + */ + protected $config; + /** * Indicates that jobs should be dispatched after all database transactions have committed. * @@ -452,6 +459,29 @@ public function setConnectionName($name) return $this; } + /** + * Get the queue configuration array. + * + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** + * Set the queue configuration array. + * + * @param array $config + * @return $this + */ + public function setConfig(array $config) + { + $this->config = $config; + + return $this; + } + /** * Get the container instance being used by the connection. * diff --git a/src/Illuminate/Queue/QueueManager.php b/src/Illuminate/Queue/QueueManager.php index 9b57be09bbd4..3eefe965db8d 100755 --- a/src/Illuminate/Queue/QueueManager.php +++ b/src/Illuminate/Queue/QueueManager.php @@ -169,9 +169,15 @@ protected function resolve($name) throw new InvalidArgumentException("The [{$name}] queue connection has not been configured."); } - return $this->getConnector($config['driver']) + $queue = $this->getConnector($config['driver']) ->connect($config) ->setConnectionName($name); + + if (method_exists($queue, 'setConfig')) { + $queue->setConfig($config); + } + + return $queue; } /** From 4281545d062a8546330c9570350afecde046fa07 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 10:13:58 -0500 Subject: [PATCH 02/12] basic failvoer test --- tests/Bus/BusDispatcherTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/Bus/BusDispatcherTest.php b/tests/Bus/BusDispatcherTest.php index d68b159f73c6..6b1646c049ce 100644 --- a/tests/Bus/BusDispatcherTest.php +++ b/tests/Bus/BusDispatcherTest.php @@ -33,6 +33,27 @@ public function testCommandsThatShouldQueueIsQueued() $dispatcher->dispatch(m::mock(ShouldQueue::class)); } + public function testCommandsCanFailoverToOtherQueues() + { + $container = new Container; + $dispatcher = new Dispatcher($container, function ($connection) { + if ($connection === 'sync-failover') { + $mock = m::mock(Queue::class); + $mock->shouldReceive('push')->once(); + return $mock; + } + + $mock = m::mock(Queue::class); + $mock->shouldReceive('getConfig')->andReturn([ + 'failover' => ['sync-failover'], + ]); + $mock->shouldReceive('push')->once()->andReturnUsing(fn () => throw new \Exception('error')); + return $mock; + }); + + $dispatcher->dispatch(m::mock(ShouldQueue::class)); + } + public function testCommandsThatShouldQueueIsQueuedUsingCustomHandler() { $container = new Container; From d70b18894c5baceeeb4071c664c67b14ed22f420 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 10 Oct 2025 15:14:24 +0000 Subject: [PATCH 03/12] Apply fixes from StyleCI --- tests/Bus/BusDispatcherTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Bus/BusDispatcherTest.php b/tests/Bus/BusDispatcherTest.php index 6b1646c049ce..2ffeb425553e 100644 --- a/tests/Bus/BusDispatcherTest.php +++ b/tests/Bus/BusDispatcherTest.php @@ -40,6 +40,7 @@ public function testCommandsCanFailoverToOtherQueues() if ($connection === 'sync-failover') { $mock = m::mock(Queue::class); $mock->shouldReceive('push')->once(); + return $mock; } @@ -48,6 +49,7 @@ public function testCommandsCanFailoverToOtherQueues() 'failover' => ['sync-failover'], ]); $mock->shouldReceive('push')->once()->andReturnUsing(fn () => throw new \Exception('error')); + return $mock; }); From b7748898513c41d735f0f3258218977f545045a9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 10:19:34 -0500 Subject: [PATCH 04/12] code cleanup --- src/Illuminate/Bus/Dispatcher.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 198cfb06f2e9..88c3ff24c599 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -240,11 +240,9 @@ public function dispatchToQueue($command) throw $e; } - $exceptionHandler = $this->container->bound(ExceptionHandler::class) - ? $this->container->make(ExceptionHandler::class) - : null; - - $exceptionHandler?->report($e); + if ($this->container->bound(ExceptionHandler::class)) { + $this->container->make(ExceptionHandler::class)->report($e); + } foreach ((array) ($queue->getConfig()['failover'] ?? []) as $failover) { try { From dfecf82ea5faf74e85bc1dbc83687b356408b2b8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 10:28:21 -0500 Subject: [PATCH 05/12] add failover --- src/Illuminate/Bus/Dispatcher.php | 6 ++++++ src/Illuminate/Bus/Events/QueueFailedOver.php | 20 +++++++++++++++++++ tests/Bus/BusDispatcherTest.php | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 src/Illuminate/Bus/Events/QueueFailedOver.php diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 88c3ff24c599..fb8456398d4a 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -3,9 +3,11 @@ namespace Illuminate\Bus; use Closure; +use Illuminate\Bus\Events\QueueFailedOver; use Illuminate\Contracts\Bus\QueueingDispatcher; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Debug\ExceptionHandler; +use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\PendingChain; @@ -244,6 +246,10 @@ public function dispatchToQueue($command) $this->container->make(ExceptionHandler::class)->report($e); } + $this->container->make(EventDispatcher::class)->dispatch( + new QueueFailedOver($command->connection ?? null, $command) + ); + foreach ((array) ($queue->getConfig()['failover'] ?? []) as $failover) { try { $command->connection = $failover; diff --git a/src/Illuminate/Bus/Events/QueueFailedOver.php b/src/Illuminate/Bus/Events/QueueFailedOver.php new file mode 100644 index 000000000000..3f0716c5c13b --- /dev/null +++ b/src/Illuminate/Bus/Events/QueueFailedOver.php @@ -0,0 +1,20 @@ +instance(EventDispatcher::class, $events = m::mock(EventDispatcher::class)); + $events->shouldReceive('dispatch'); + $dispatcher->dispatch(m::mock(ShouldQueue::class)); } From 39455dfebaa12ddebf54d0cd01fcd56a5057de3e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 10 Oct 2025 15:28:39 +0000 Subject: [PATCH 06/12] Apply fixes from StyleCI --- src/Illuminate/Bus/Events/QueueFailedOver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Bus/Events/QueueFailedOver.php b/src/Illuminate/Bus/Events/QueueFailedOver.php index 3f0716c5c13b..23903a4ee10f 100644 --- a/src/Illuminate/Bus/Events/QueueFailedOver.php +++ b/src/Illuminate/Bus/Events/QueueFailedOver.php @@ -2,8 +2,6 @@ namespace Illuminate\Bus\Events; -use Illuminate\Bus\Batch; - class QueueFailedOver { /** From f11fa985d6f67eb1fd404e0766275d7101cb70d3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 10:30:43 -0500 Subject: [PATCH 07/12] code cleaning --- src/Illuminate/Bus/Dispatcher.php | 46 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index fb8456398d4a..872b6f04e71a 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -246,23 +246,7 @@ public function dispatchToQueue($command) $this->container->make(ExceptionHandler::class)->report($e); } - $this->container->make(EventDispatcher::class)->dispatch( - new QueueFailedOver($command->connection ?? null, $command) - ); - - foreach ((array) ($queue->getConfig()['failover'] ?? []) as $failover) { - try { - $command->connection = $failover; - - return $this->dispatchToQueue($command); - } catch (Throwable $failoverException) { - // - } - } - - if (isset($failoverException)) { - throw $failoverException; - } + $this->pushToFailoverQueue($queue, $command); } } @@ -282,6 +266,34 @@ protected function pushCommandToQueue($queue, $command) return $queue->push($command, queue: $command->queue ?? null); } + /** + * Push the command to its failover queue if possible. + * + * @param \Illuminate\Contracts\Queue\Queue $queue + * @param mixed $connection + * @return void + */ + protected function pushToFailoverQueue($queue, $command) + { + $this->container->make(EventDispatcher::class)->dispatch( + new QueueFailedOver($command->connection ?? null, $command) + ); + + foreach ((array) ($queue->getConfig()['failover'] ?? []) as $failover) { + try { + $command->connection = $failover; + + return $this->dispatchToQueue($command); + } catch (Throwable $failoverException) { + // + } + } + + if (isset($failoverException)) { + throw $failoverException; + } + } + /** * Dispatch a command to its appropriate handler after the current process. * From 3459279dd3852138b49bcfd45a7c0611a7034c11 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 10:31:24 -0500 Subject: [PATCH 08/12] rename variable --- src/Illuminate/Bus/Dispatcher.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 872b6f04e71a..737784b86161 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -284,13 +284,13 @@ protected function pushToFailoverQueue($queue, $command) $command->connection = $failover; return $this->dispatchToQueue($command); - } catch (Throwable $failoverException) { + } catch (Throwable $e) { // } } - if (isset($failoverException)) { - throw $failoverException; + if (isset($e)) { + throw $e; } } From e6b01f1cafcbc172042c0cb8be32aafae7c56897 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 11:09:50 -0500 Subject: [PATCH 09/12] rearchitect --- src/Illuminate/Bus/Dispatcher.php | 58 +------ .../Queue/Connectors/FailoverConnector.php | 32 ++++ .../{Bus => Queue}/Events/QueueFailedOver.php | 6 +- src/Illuminate/Queue/FailoverQueue.php | 153 ++++++++++++++++++ src/Illuminate/Queue/QueueServiceProvider.php | 20 ++- tests/Bus/BusDispatcherTest.php | 27 ---- 6 files changed, 211 insertions(+), 85 deletions(-) create mode 100644 src/Illuminate/Queue/Connectors/FailoverConnector.php rename src/Illuminate/{Bus => Queue}/Events/QueueFailedOver.php (54%) create mode 100644 src/Illuminate/Queue/FailoverQueue.php diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 737784b86161..891573219c5a 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -3,11 +3,8 @@ namespace Illuminate\Bus; use Closure; -use Illuminate\Bus\Events\QueueFailedOver; use Illuminate\Contracts\Bus\QueueingDispatcher; use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Debug\ExceptionHandler; -use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\PendingChain; @@ -16,7 +13,6 @@ use Illuminate\Queue\Jobs\SyncJob; use Illuminate\Support\Collection; use RuntimeException; -use Throwable; class Dispatcher implements QueueingDispatcher { @@ -64,9 +60,6 @@ class Dispatcher implements QueueingDispatcher /** * Create a new command dispatcher instance. - * - * @param \Illuminate\Contracts\Container\Container $container - * @param \Closure|null $queueResolver */ public function __construct(Container $container, ?Closure $queueResolver = null) { @@ -143,7 +136,6 @@ public function dispatchNow($command, $handler = null) /** * Attempt to find the batch with the given ID. * - * @param string $batchId * @return \Illuminate\Bus\Batch|null */ public function findBatch(string $batchId) @@ -231,23 +223,11 @@ public function dispatchToQueue($command) throw new RuntimeException('Queue resolver did not return a Queue implementation.'); } - try { - if (method_exists($command, 'queue')) { - return $command->queue($queue, $command); - } - - return $this->pushCommandToQueue($queue, $command); - } catch (Throwable $e) { - if (empty($queue->getConfig()['failover'] ?? [])) { - throw $e; - } - - if ($this->container->bound(ExceptionHandler::class)) { - $this->container->make(ExceptionHandler::class)->report($e); - } - - $this->pushToFailoverQueue($queue, $command); + if (method_exists($command, 'queue')) { + return $command->queue($queue, $command); } + + return $this->pushCommandToQueue($queue, $command); } /** @@ -266,34 +246,6 @@ protected function pushCommandToQueue($queue, $command) return $queue->push($command, queue: $command->queue ?? null); } - /** - * Push the command to its failover queue if possible. - * - * @param \Illuminate\Contracts\Queue\Queue $queue - * @param mixed $connection - * @return void - */ - protected function pushToFailoverQueue($queue, $command) - { - $this->container->make(EventDispatcher::class)->dispatch( - new QueueFailedOver($command->connection ?? null, $command) - ); - - foreach ((array) ($queue->getConfig()['failover'] ?? []) as $failover) { - try { - $command->connection = $failover; - - return $this->dispatchToQueue($command); - } catch (Throwable $e) { - // - } - } - - if (isset($e)) { - throw $e; - } - } - /** * Dispatch a command to its appropriate handler after the current process. * @@ -317,7 +269,6 @@ public function dispatchAfterResponse($command, $handler = null) /** * Set the pipes through which commands should be piped before dispatching. * - * @param array $pipes * @return $this */ public function pipeThrough(array $pipes) @@ -330,7 +281,6 @@ public function pipeThrough(array $pipes) /** * Map a command to a handler. * - * @param array $map * @return $this */ public function map(array $map) diff --git a/src/Illuminate/Queue/Connectors/FailoverConnector.php b/src/Illuminate/Queue/Connectors/FailoverConnector.php new file mode 100644 index 000000000000..7067aace1ffc --- /dev/null +++ b/src/Illuminate/Queue/Connectors/FailoverConnector.php @@ -0,0 +1,32 @@ +manager, + $this->events, + $config['connections'], + ); + } +} diff --git a/src/Illuminate/Bus/Events/QueueFailedOver.php b/src/Illuminate/Queue/Events/QueueFailedOver.php similarity index 54% rename from src/Illuminate/Bus/Events/QueueFailedOver.php rename to src/Illuminate/Queue/Events/QueueFailedOver.php index 23903a4ee10f..bf9ad63c6ac1 100644 --- a/src/Illuminate/Bus/Events/QueueFailedOver.php +++ b/src/Illuminate/Queue/Events/QueueFailedOver.php @@ -1,14 +1,14 @@ manager->connection($this->connections[0])->size($queue); + } + + /** + * Get the number of pending jobs. + * + * @param string|null $queue + * @return int + */ + public function pendingSize($queue = null) + { + return $this->manager->connection($this->connections[0])->pendingSize($queue); + } + + /** + * Get the number of delayed jobs. + * + * @param string|null $queue + * @return int + */ + public function delayedSize($queue = null) + { + return $this->manager->connection($this->connections[0])->delayedSize($queue); + } + + /** + * Get the number of reserved jobs. + * + * @param string|null $queue + * @return int + */ + public function reservedSize($queue = null) + { + return $this->manager->connection($this->connections[0])->reservedSize($queue); + } + + /** + * Get the creation timestamp of the oldest pending job, excluding delayed jobs. + * + * @param string|null $queue + * @return int|null + */ + public function creationTimeOfOldestPendingJob($queue = null) + { + return $this->manager + ->connection($this->connections[0]) + ->creationTimeOfOldestPendingJob($queue); + } + + /** + * Push a new job onto the queue. + * + * @param object|string $job + * @param mixed $data + * @param string|null $queue + * @return mixed + */ + public function push($job, $data = '', $queue = null) + { + foreach ($this->connections as $connection) { + try { + return $this->manager->connection($connection)->push($job, $data, $queue); + } catch (Throwable $e) { + $failed = true; + + $this->events->dispatch(new QueueFailedOver($connection, $job)); + } + } + + throw $e; + } + + /** + * Push a raw payload onto the queue. + * + * @param string $payload + * @param string|null $queue + * @return mixed + */ + public function pushRaw($payload, $queue = null, array $options = []) + { + foreach ($this->connections as $connection) { + try { + return $this->manager->connection($connection)->pushRaw($payload, $queue, $options); + } catch (Throwable $e) { + // + } + } + + throw $e; + } + + /** + * Push a new job onto the queue after (n) seconds. + * + * @param \DateTimeInterface|\DateInterval|int $delay + * @param string $job + * @param mixed $data + * @param string|null $queue + * @return mixed + */ + public function later($delay, $job, $data = '', $queue = null) + { + foreach ($this->connections as $connection) { + try { + return $this->manager->connection($connection)->later($delay, $job, $data, $queue); + } catch (Throwable $e) { + $this->events->dispatch(new QueueFailedOver($connection, $job)); + } + } + + throw $e; + } + + /** + * Pop the next job off of the queue. + * + * @param string|null $queue + * @return \Illuminate\Contracts\Queue\Job|null + */ + public function pop($queue = null) + { + return $this->manager->connection($this->connections[0])->pop($queue); + } +} diff --git a/src/Illuminate/Queue/QueueServiceProvider.php b/src/Illuminate/Queue/QueueServiceProvider.php index 3b1d97208da0..954b7a207ab7 100755 --- a/src/Illuminate/Queue/QueueServiceProvider.php +++ b/src/Illuminate/Queue/QueueServiceProvider.php @@ -4,9 +4,11 @@ use Aws\DynamoDb\DynamoDbClient; use Illuminate\Contracts\Debug\ExceptionHandler; +use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Queue\Connectors\BeanstalkdConnector; use Illuminate\Queue\Connectors\DatabaseConnector; +use Illuminate\Queue\Connectors\FailoverConnector; use Illuminate\Queue\Connectors\NullConnector; use Illuminate\Queue\Connectors\RedisConnector; use Illuminate\Queue\Connectors\SqsConnector; @@ -102,7 +104,7 @@ protected function registerConnection() */ public function registerConnectors($manager) { - foreach (['Null', 'Sync', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) { + foreach (['Null', 'Sync', 'Failover', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) { $this->{"register{$connector}Connector"}($manager); } } @@ -133,6 +135,22 @@ protected function registerSyncConnector($manager) }); } + /** + * Register the Failover queue connector. + * + * @param \Illuminate\Queue\QueueManager $manager + * @return void + */ + protected function registerFailoverConnector($manager) + { + $manager->addConnector('failover', function () use ($manager) { + return new FailoverConnector( + $manager, + $this->app->make(EventDispatcher::class) + ); + }); + } + /** * Register the database queue connector. * diff --git a/tests/Bus/BusDispatcherTest.php b/tests/Bus/BusDispatcherTest.php index 175f055dd5d6..1fdcfd9c2398 100644 --- a/tests/Bus/BusDispatcherTest.php +++ b/tests/Bus/BusDispatcherTest.php @@ -34,33 +34,6 @@ public function testCommandsThatShouldQueueIsQueued() $dispatcher->dispatch(m::mock(ShouldQueue::class)); } - public function testCommandsCanFailoverToOtherQueues() - { - $container = new Container; - - $dispatcher = new Dispatcher($container, function ($connection) { - if ($connection === 'sync-failover') { - $mock = m::mock(Queue::class); - $mock->shouldReceive('push')->once(); - - return $mock; - } - - $mock = m::mock(Queue::class); - $mock->shouldReceive('getConfig')->andReturn([ - 'failover' => ['sync-failover'], - ]); - $mock->shouldReceive('push')->once()->andReturnUsing(fn () => throw new \Exception('error')); - - return $mock; - }); - - $container->instance(EventDispatcher::class, $events = m::mock(EventDispatcher::class)); - $events->shouldReceive('dispatch'); - - $dispatcher->dispatch(m::mock(ShouldQueue::class)); - } - public function testCommandsThatShouldQueueIsQueuedUsingCustomHandler() { $container = new Container; From 800ffa58a49b30c905056847b560b463ddd3bac9 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 10 Oct 2025 16:10:11 +0000 Subject: [PATCH 10/12] Apply fixes from StyleCI --- src/Illuminate/Queue/Connectors/FailoverConnector.php | 3 ++- src/Illuminate/Queue/FailoverQueue.php | 3 ++- tests/Bus/BusDispatcherTest.php | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Queue/Connectors/FailoverConnector.php b/src/Illuminate/Queue/Connectors/FailoverConnector.php index 7067aace1ffc..5472d23a6e5f 100644 --- a/src/Illuminate/Queue/Connectors/FailoverConnector.php +++ b/src/Illuminate/Queue/Connectors/FailoverConnector.php @@ -14,7 +14,8 @@ class FailoverConnector implements ConnectorInterface public function __construct( protected QueueManager $manager, protected Dispatcher $events - ) {} + ) { + } /** * Establish a queue connection. diff --git a/src/Illuminate/Queue/FailoverQueue.php b/src/Illuminate/Queue/FailoverQueue.php index d1be80b2f1ac..e8e5b8de2e25 100644 --- a/src/Illuminate/Queue/FailoverQueue.php +++ b/src/Illuminate/Queue/FailoverQueue.php @@ -16,7 +16,8 @@ public function __construct( public QueueManager $manager, public EventDispatcher $events, public array $connections - ) {} + ) { + } /** * Get the size of the queue. diff --git a/tests/Bus/BusDispatcherTest.php b/tests/Bus/BusDispatcherTest.php index 1fdcfd9c2398..d68b159f73c6 100644 --- a/tests/Bus/BusDispatcherTest.php +++ b/tests/Bus/BusDispatcherTest.php @@ -6,7 +6,6 @@ use Illuminate\Bus\Queueable; use Illuminate\Config\Repository as Config; use Illuminate\Container\Container; -use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; From 9baa909cbcad1e4c3301039a4107deb4a70a8c9d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 11:12:04 -0500 Subject: [PATCH 11/12] remove variable --- src/Illuminate/Queue/FailoverQueue.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Queue/FailoverQueue.php b/src/Illuminate/Queue/FailoverQueue.php index e8e5b8de2e25..beeaf6827bf4 100644 --- a/src/Illuminate/Queue/FailoverQueue.php +++ b/src/Illuminate/Queue/FailoverQueue.php @@ -90,8 +90,6 @@ public function push($job, $data = '', $queue = null) try { return $this->manager->connection($connection)->push($job, $data, $queue); } catch (Throwable $e) { - $failed = true; - $this->events->dispatch(new QueueFailedOver($connection, $job)); } } From 723d0da0b3e04de1fcb90a4ae9c17c0d75082c50 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Oct 2025 11:15:36 -0500 Subject: [PATCH 12/12] add tests --- tests/Queue/FailoverQueueTest.php | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Queue/FailoverQueueTest.php diff --git a/tests/Queue/FailoverQueueTest.php b/tests/Queue/FailoverQueueTest.php new file mode 100644 index 000000000000..cd3ca3f56b77 --- /dev/null +++ b/tests/Queue/FailoverQueueTest.php @@ -0,0 +1,46 @@ +shouldReceive('connection')->once()->with('redis')->andReturn( + $redis = m::mock('stdClass'), + ); + + $queue->shouldReceive('connection')->once()->with('sync')->andReturn( + $sync = m::mock('stdClass'), + ); + + $events->shouldReceive('dispatch')->once(); + + $redis->shouldReceive('push')->once()->andReturnUsing( + fn () => throw new \Exception('error') + ); + + $sync->shouldReceive('push')->once(); + + $failover->push('some-job'); + } +}