From 2b1581875a189b8f4d7e2497ad4a94f7d0f4ae96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Fri, 9 Oct 2020 22:06:28 +0200 Subject: [PATCH] Fixes the queue for beta 14 (#2363) - rewrite the queue handling for illuminate 6+ - implement missing maintenance mode callable for queue Worker - Ensure we resolve append the queue commands once the queue bindings are loaded - Override WorkCommand because it needs the maintenance flag. It tries to use the isDownForMaintenance method from the Container assuming it is a Laravel Application. Circumvented this issue by resolving our Config from IOC instead. --- src/Queue/Console/WorkCommand.php | 27 +++++++++++++ src/Queue/HackyManagerForWorker.php | 61 ----------------------------- src/Queue/QueueServiceProvider.php | 25 +++++++----- 3 files changed, 43 insertions(+), 70 deletions(-) create mode 100644 src/Queue/Console/WorkCommand.php delete mode 100644 src/Queue/HackyManagerForWorker.php diff --git a/src/Queue/Console/WorkCommand.php b/src/Queue/Console/WorkCommand.php new file mode 100644 index 000000000..677fbe679 --- /dev/null +++ b/src/Queue/Console/WorkCommand.php @@ -0,0 +1,27 @@ +option('force')) { + return false; + } + + /** @var Config $config */ + $config = $this->laravel->make(Config::class); + + return $config->inMaintenanceMode(); + } +} diff --git a/src/Queue/HackyManagerForWorker.php b/src/Queue/HackyManagerForWorker.php deleted file mode 100644 index 9a22b2903..000000000 --- a/src/Queue/HackyManagerForWorker.php +++ /dev/null @@ -1,61 +0,0 @@ -factory = $factory; - } - - /** - * Resolve a queue connection instance. - * - * @param string $name - * @return \Illuminate\Contracts\Queue\Queue - */ - public function connection($name = null) - { - return $this->factory->connection($name); - } - - /** - * Determine if the application is in maintenance mode. - * - * @return bool - */ - public function isDownForMaintenance() - { - return false; - } -} diff --git a/src/Queue/QueueServiceProvider.php b/src/Queue/QueueServiceProvider.php index 3db372ee2..ac9024516 100644 --- a/src/Queue/QueueServiceProvider.php +++ b/src/Queue/QueueServiceProvider.php @@ -9,8 +9,8 @@ namespace Flarum\Queue; -use Flarum\Console\Event\Configuring; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Foundation\Config; use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Foundation\Paths; @@ -22,6 +22,7 @@ use Illuminate\Queue\Console as Commands; use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Failed\NullFailedJobProvider; use Illuminate\Queue\Listener as QueueListener; +use Illuminate\Queue\QueueManager; use Illuminate\Queue\SyncQueue; use Illuminate\Queue\Worker; @@ -34,7 +35,7 @@ class QueueServiceProvider extends AbstractServiceProvider Commands\ListFailedCommand::class, Commands\RestartCommand::class, Commands\RetryCommand::class, - Commands\WorkCommand::class, + Console\WorkCommand::class, ]; public function register() @@ -61,10 +62,16 @@ class QueueServiceProvider extends AbstractServiceProvider }); $this->app->singleton(Worker::class, function ($app) { + /** @var Config $config */ + $config = $app->make(Config::class); + return new Worker( - new HackyManagerForWorker($app[Factory::class]), + new QueueManager($app), $app['events'], - $app[ExceptionHandling::class] + $app[ExceptionHandling::class], + function () use ($config) { + return $config->inMaintenanceMode(); + } ); }); @@ -110,17 +117,17 @@ class QueueServiceProvider extends AbstractServiceProvider protected function registerCommands() { - $this->app['events']->listen(Configuring::class, function (Configuring $event) { + $this->app->extend('flarum.console.commands', function ($commands) { $queue = $this->app->make(Queue::class); // There is no need to have the queue commands when using the sync driver. if ($queue instanceof SyncQueue) { - return; + return $commands; } - foreach ($this->commands as $command) { - $event->addCommand($command); - } + // Otherwise add our commands, while allowing them to be overridden by those + // already added through the container. + return array_merge($this->commands, $commands); }); }