feat: Restart the queue worker after cache clearing, ext enable/disable, save settings (#3565)

* Add queue restarter
* Update framework/core/src/Queue/QueueRestarter.php
This commit is contained in:
Ian Morland 2022-08-01 23:49:58 +01:00 committed by GitHub
parent 7147d39975
commit da855c654e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?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 Flarum\Extension\Event\Disabled;
use Flarum\Extension\Event\Enabled;
use Flarum\Foundation\Event\ClearingCache;
use Flarum\Settings\Event\Saved;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Queue\Console\RestartCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
class QueueRestarter
{
/**
* @var Container
*/
protected $container;
/**
* @var RestartCommand
*/
protected $command;
public function __construct(Container $container, RestartCommand $command)
{
$this->container = $container;
$this->command = $command;
}
public function subscribe(Dispatcher $events)
{
$events->listen([
ClearingCache::class, Saved::class,
Enabled::class, Disabled::class
], [$this, 'restart']);
}
public function restart()
{
$this->command->setLaravel($this->container);
$this->command->run(
new ArrayInput([]),
new NullOutput
);
}
}

View File

@ -161,5 +161,7 @@ class QueueServiceProvider extends AbstractServiceProvider
}
}
});
$events->subscribe(QueueRestarter::class);
}
}