This commit is contained in:
2023-08-11 02:18:04 +08:00
parent 8fb3fd699e
commit 65fa64e6b7
3 changed files with 21 additions and 13 deletions
+2
View File
@@ -11,7 +11,9 @@ use Kiri\Server\Config as SConfig;
use Kiri\Server\Constant;
use Kiri\Server\Events\OnServerBeforeStart;
use Kiri\Server\Events\OnShutdown;
use Kiri\Server\Events\OnWorkerStart;
use Kiri\Server\Handler\OnServer;
use Kiri\Server\HotReload;
use Kiri\Server\ServerInterface;
use Kiri\Server\Task\TaskInterface;
use Kiri\Server\Task\Task;
+10
View File
@@ -5,7 +5,9 @@ namespace Kiri\Server;
use Exception;
use Kiri\Di\Context;
use Kiri\Router\Router;
use Kiri\Server\Abstracts\BaseProcess;
use Kiri\Server\Events\OnWorkerStart;
use ReflectionException;
use Swoole\Coroutine;
use Swoole\Event;
@@ -31,6 +33,14 @@ class HotReload extends BaseProcess
protected mixed $inotify = null;
/**
* @param Router $router
*/
public function __construct(public Router $router)
{
on(OnWorkerStart::class, [$this->router, 'scan_build_route']);
}
/**
* @return string
*/
+9 -13
View File
@@ -14,7 +14,7 @@ use Kiri\Server\Events\OnWorkerStop;
use Kiri\Server\Abstracts\AsyncServer;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Kiri\Server\Events\OnServerBeforeStart;
use Swoole\Timer;
@@ -50,12 +50,13 @@ class Server
/**
* @param $process
* @throws Exception
* @return void
*/
public function addProcess($process): void
public function init(): void
{
$this->manager->addProcess($process);
on(OnWorkerStop::class, [Timer::class, 'clearAll'], 9999);
on(OnWorkerStart::class, [$this, 'setWorkerName']);
on(OnTaskerStart::class, [$this, 'setTaskerName']);
}
@@ -65,16 +66,11 @@ class Server
*/
public function start(): void
{
on(OnWorkerStop::class, [Timer::class, 'clearAll'], 9999);
on(OnWorkerStart::class, [$this, 'setWorkerName']);
on(OnTaskerStart::class, [$this, 'setTaskerName']);
if (\config('reload.hot') === false) {
$this->router->scan_build_route();
if (\config('reload.hot', false) === true) {
$this->manager->addProcess(HotReload::class);
} else {
on(OnWorkerStart::class, [$this->router, 'scan_build_route']);
$this->addProcess(HotReload::class);
$this->router->scan_build_route();
}
$this->manager->initCoreServers(\config('server', []), $this->daemon);
$this->manager->start();
}