mirror of
https://github.com/flarum/framework.git
synced 2025-03-10 20:31:24 +08:00
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.
This commit is contained in:
parent
32dc54becc
commit
84ce740489
27
framework/core/src/Queue/Console/WorkCommand.php
Normal file
27
framework/core/src/Queue/Console/WorkCommand.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Queue\Console;
|
||||||
|
|
||||||
|
use Flarum\Foundation\Config;
|
||||||
|
|
||||||
|
class WorkCommand extends \Illuminate\Queue\Console\WorkCommand
|
||||||
|
{
|
||||||
|
protected function downForMaintenance()
|
||||||
|
{
|
||||||
|
if ($this->option('force')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Config $config */
|
||||||
|
$config = $this->laravel->make(Config::class);
|
||||||
|
|
||||||
|
return $config->inMaintenanceMode();
|
||||||
|
}
|
||||||
|
}
|
@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* For detailed copyright and license information, please view the
|
|
||||||
* LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Queue;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Queue\Factory;
|
|
||||||
use Illuminate\Queue\QueueManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A hacky workaround to avoid injecting an entire QueueManager (which we don't
|
|
||||||
* want to build) into Laravel's queue worker class.
|
|
||||||
*
|
|
||||||
* Laravel 6.0 will clean this up; once we upgrade, we can remove this hack and
|
|
||||||
* directly inject the factory.
|
|
||||||
*/
|
|
||||||
class HackyManagerForWorker extends QueueManager implements Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Factory
|
|
||||||
*/
|
|
||||||
private $factory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HackyManagerForWorker constructor.
|
|
||||||
*
|
|
||||||
* Needs a real connection factory to delegate to.
|
|
||||||
*
|
|
||||||
* @param Factory $factory
|
|
||||||
*/
|
|
||||||
public function __construct(Factory $factory)
|
|
||||||
{
|
|
||||||
$this->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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
namespace Flarum\Queue;
|
namespace Flarum\Queue;
|
||||||
|
|
||||||
use Flarum\Console\Event\Configuring;
|
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
|
use Flarum\Foundation\Config;
|
||||||
use Flarum\Foundation\ErrorHandling\Registry;
|
use Flarum\Foundation\ErrorHandling\Registry;
|
||||||
use Flarum\Foundation\ErrorHandling\Reporter;
|
use Flarum\Foundation\ErrorHandling\Reporter;
|
||||||
use Flarum\Foundation\Paths;
|
use Flarum\Foundation\Paths;
|
||||||
@ -22,6 +22,7 @@ use Illuminate\Queue\Console as Commands;
|
|||||||
use Illuminate\Queue\Events\JobFailed;
|
use Illuminate\Queue\Events\JobFailed;
|
||||||
use Illuminate\Queue\Failed\NullFailedJobProvider;
|
use Illuminate\Queue\Failed\NullFailedJobProvider;
|
||||||
use Illuminate\Queue\Listener as QueueListener;
|
use Illuminate\Queue\Listener as QueueListener;
|
||||||
|
use Illuminate\Queue\QueueManager;
|
||||||
use Illuminate\Queue\SyncQueue;
|
use Illuminate\Queue\SyncQueue;
|
||||||
use Illuminate\Queue\Worker;
|
use Illuminate\Queue\Worker;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ class QueueServiceProvider extends AbstractServiceProvider
|
|||||||
Commands\ListFailedCommand::class,
|
Commands\ListFailedCommand::class,
|
||||||
Commands\RestartCommand::class,
|
Commands\RestartCommand::class,
|
||||||
Commands\RetryCommand::class,
|
Commands\RetryCommand::class,
|
||||||
Commands\WorkCommand::class,
|
Console\WorkCommand::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function register()
|
public function register()
|
||||||
@ -61,10 +62,16 @@ class QueueServiceProvider extends AbstractServiceProvider
|
|||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton(Worker::class, function ($app) {
|
$this->app->singleton(Worker::class, function ($app) {
|
||||||
|
/** @var Config $config */
|
||||||
|
$config = $app->make(Config::class);
|
||||||
|
|
||||||
return new Worker(
|
return new Worker(
|
||||||
new HackyManagerForWorker($app[Factory::class]),
|
new QueueManager($app),
|
||||||
$app['events'],
|
$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()
|
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);
|
$queue = $this->app->make(Queue::class);
|
||||||
|
|
||||||
// There is no need to have the queue commands when using the sync driver.
|
// There is no need to have the queue commands when using the sync driver.
|
||||||
if ($queue instanceof SyncQueue) {
|
if ($queue instanceof SyncQueue) {
|
||||||
return;
|
return $commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->commands as $command) {
|
// Otherwise add our commands, while allowing them to be overridden by those
|
||||||
$event->addCommand($command);
|
// already added through the container.
|
||||||
}
|
return array_merge($this->commands, $commands);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user