diff --git a/HttpServer/Events/OnPipeMessage.php b/HttpServer/Events/OnPipeMessage.php index 1ec41374..1633ca41 100644 --- a/HttpServer/Events/OnPipeMessage.php +++ b/HttpServer/Events/OnPipeMessage.php @@ -28,13 +28,11 @@ class OnPipeMessage extends Callback */ public function onHandler(Server $server, int $src_worker_id, $message) { - // TODO: Implement onHandler() method. - var_dump($message); - if (is_array($message) && ($message[1] ?? null) instanceof Loader) { + if ($message instanceof Loader) { if ($src_worker_id > $server->setting['worker_num']) { - $message[1]->loadByDirectory(MODEL_PATH); + $message->loadByDirectory(MODEL_PATH); } else { - $message[1]->loadByDirectory(APP_PATH); + $message->loadByDirectory(APP_PATH); } } else { $events = Snowflake::app()->getEvent(); diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index ac90a0c5..577d4b92 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -39,6 +39,10 @@ class OnWorkerStart extends Callback name($server->worker_pid, $worker_id >= $server->setting['worker_num'] ? 'task' : 'worker'); + /** @var ServerInotify $inotify */ + $inotify = Snowflake::app()->get(ServerInotify::class); + $inotify->getLoader($worker_id); + if ($worker_id >= $server->setting['worker_num']) { $this->onTask($server, $worker_id); } else { diff --git a/System/Process/ServerInotify.php b/System/Process/ServerInotify.php index 193ade05..651f673f 100644 --- a/System/Process/ServerInotify.php +++ b/System/Process/ServerInotify.php @@ -46,12 +46,15 @@ class ServerInotify extends Process /** - * @return mixed + * @param $workerId + * @throws Exception */ - public function getLoader() + public function getLoader($workerId) { $annotation = Snowflake::app()->getAnnotation(); - return $annotation->getLoader(); + + $server = Snowflake::app()->getSwoole(); + $server->sendMessage($annotation->getLoader(), $workerId); } @@ -74,16 +77,6 @@ class ServerInotify extends Process if (!is_dir($dir)) continue; $this->watch($dir); } - - $worker = Snowflake::app()->getSwoole(); - - $workerNum = $worker->setting['worker_num']; - $task_worker_num = $worker->setting['task_worker_num'] ?? 0; - - for ($i = 0; $i < $workerNum + $task_worker_num; $i++) { - $worker->sendMessage(['reload', $this->getLoader()], $i); - } - Event::add($this->inotify, [$this, 'check']); Event::wait(); } else {