From ba3009086dc33912364056035efce5d60075a70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 16 Apr 2021 15:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Events/OnWorkerStart.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 810f2032..96181225 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -36,12 +36,11 @@ class OnWorkerStart extends Callback $annotation = Snowflake::app()->getAnnotation(); $annotation->setLoader(unserialize($content)); - $annotation->runtime(directory('app')); if ($worker_id < $server->setting['worker_num']) { - $this->onWorker($server); + $this->onWorker($server, $annotation); } else { - $this->onTask($server); + $this->onTask($server, $annotation); } } @@ -59,13 +58,16 @@ class OnWorkerStart extends Callback /** * @param Server $server + * @param Annotation $annotation * @throws ConfigException * @throws Exception */ - public function onTask(Server $server) + public function onTask(Server $server, Annotation $annotation) { putenv('environmental=' . Snowflake::TASK); + $annotation->runtime(directory('app'),CONTROLLER_PATH); + name($server->worker_pid, 'Task#' . $server->worker_id); Snowflake::setTaskId($server->worker_pid); @@ -76,13 +78,16 @@ class OnWorkerStart extends Callback /** * @param Server $server + * @param Annotation $annotation * @throws Exception */ - public function onWorker(Server $server) + public function onWorker(Server $server, Annotation $annotation) { try { name($server->worker_pid, 'Worker#' . $server->worker_id); + $annotation->runtime(directory('app')); + Snowflake::setWorkerId($server->worker_pid); putenv('environmental=' . Snowflake::WORKER);