This commit is contained in:
2021-09-06 14:20:04 +08:00
parent 3eeca0315a
commit 728f95492f
3 changed files with 20 additions and 13 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ use Kiri\Abstracts\Config;
use Kiri\Error\LoggerProcess;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use Kiri\Rpc\Service;
use Kiri\Rpc\RpcProvider;
use Server\Events\OnShutdown;
use Swoole\Runtime;
@@ -75,7 +75,7 @@ class Server extends HttpService
$rpcService = Config::get('rpc', []);
if (!empty($rpcService)) {
Service::addRpcListener($this->manager, $rpcService);
RpcProvider::addRpcListener($this->manager, $rpcService);
}
$processes = array_merge($this->process, Config::get('processes', []));
+4 -4
View File
@@ -49,10 +49,10 @@ class OnServerWorker extends \Server\Abstracts\Server
}
/**
* @param $workerId
* @throws \Exception
*/
/**
* @param OnBeforeWorkerStart $worker
* @throws Exception
*/
public function setConfigure(OnBeforeWorkerStart $worker)
{
ServerManager::setEnv('worker', $worker->workerId);
+14 -7
View File
@@ -19,25 +19,32 @@ class OnWorkerStart implements EventDispatcherInterface
{
/**
* @var Annotation
*/
#[Inject(Annotation::class)]
public Annotation $annotation;
/**
* @var Router
*/
#[Inject(Router::class)]
public Router $router;
/**
* @param object $event
* @return object|void
* @throws \Kiri\Exception\ConfigException
* @throws \ReflectionException
*/
/**
* @param object $event
* @return void
* @throws ConfigException
* @throws ReflectionException
* @throws Exception
*/
public function dispatch(object $event)
{
$isWorker = $event->workerId < $event->server->setting['worker_num'];
$this->annotation->read(APP_PATH . 'app', 'App', $isWorker ? [] : [CONTROLLER_PATH]);
$this->annotation->read(APP_PATH . 'app', 'App');
$this->interpretDirectory();
if ($isWorker) {
ServerManager::setEnv('environmental', Kiri::WORKER);