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); }); }