qqq
This commit is contained in:
@@ -11,7 +11,9 @@ use Kiri\Server\Config as SConfig;
|
|||||||
use Kiri\Server\Constant;
|
use Kiri\Server\Constant;
|
||||||
use Kiri\Server\Events\OnServerBeforeStart;
|
use Kiri\Server\Events\OnServerBeforeStart;
|
||||||
use Kiri\Server\Events\OnShutdown;
|
use Kiri\Server\Events\OnShutdown;
|
||||||
|
use Kiri\Server\Events\OnWorkerStart;
|
||||||
use Kiri\Server\Handler\OnServer;
|
use Kiri\Server\Handler\OnServer;
|
||||||
|
use Kiri\Server\HotReload;
|
||||||
use Kiri\Server\ServerInterface;
|
use Kiri\Server\ServerInterface;
|
||||||
use Kiri\Server\Task\TaskInterface;
|
use Kiri\Server\Task\TaskInterface;
|
||||||
use Kiri\Server\Task\Task;
|
use Kiri\Server\Task\Task;
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ namespace Kiri\Server;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Di\Context;
|
use Kiri\Di\Context;
|
||||||
|
use Kiri\Router\Router;
|
||||||
use Kiri\Server\Abstracts\BaseProcess;
|
use Kiri\Server\Abstracts\BaseProcess;
|
||||||
|
use Kiri\Server\Events\OnWorkerStart;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Event;
|
use Swoole\Event;
|
||||||
@@ -31,6 +33,14 @@ class HotReload extends BaseProcess
|
|||||||
protected mixed $inotify = null;
|
protected mixed $inotify = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Router $router
|
||||||
|
*/
|
||||||
|
public function __construct(public Router $router)
|
||||||
|
{
|
||||||
|
on(OnWorkerStart::class, [$this->router, 'scan_build_route']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
+9
-13
@@ -14,7 +14,7 @@ use Kiri\Server\Events\OnWorkerStop;
|
|||||||
use Kiri\Server\Abstracts\AsyncServer;
|
use Kiri\Server\Abstracts\AsyncServer;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use ReflectionException;
|
use Kiri\Server\Events\OnServerBeforeStart;
|
||||||
use Swoole\Timer;
|
use Swoole\Timer;
|
||||||
|
|
||||||
|
|
||||||
@@ -50,12 +50,13 @@ class Server
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $process
|
* @return void
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
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
|
public function start(): void
|
||||||
{
|
{
|
||||||
on(OnWorkerStop::class, [Timer::class, 'clearAll'], 9999);
|
if (\config('reload.hot', false) === true) {
|
||||||
on(OnWorkerStart::class, [$this, 'setWorkerName']);
|
$this->manager->addProcess(HotReload::class);
|
||||||
on(OnTaskerStart::class, [$this, 'setTaskerName']);
|
|
||||||
if (\config('reload.hot') === false) {
|
|
||||||
$this->router->scan_build_route();
|
|
||||||
} else {
|
} else {
|
||||||
on(OnWorkerStart::class, [$this->router, 'scan_build_route']);
|
$this->router->scan_build_route();
|
||||||
$this->addProcess(HotReload::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->manager->initCoreServers(\config('server', []), $this->daemon);
|
$this->manager->initCoreServers(\config('server', []), $this->daemon);
|
||||||
$this->manager->start();
|
$this->manager->start();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user