From b93d4a32f341da90defeb280ef571d7f93e50680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 26 Feb 2021 18:25:45 +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 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index cc39d3c8..a15d5d14 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -36,25 +36,34 @@ class OnWorkerStart extends Callback swoole_set_process_name($get_name); } + go(function () use ($server) { + Coroutine\System::waitPid($server->worker_pid); + }); + putenv('workerId=' . ($worker_id >= $server->setting['worker_num'] ? 'Task' : 'Worker') . '.' . $worker_id); if ($worker_id >= $server->setting['worker_num']) { fire(Event::SERVER_TASK_START); - $this->onSign(); + $this->onTaskSignal($server, $worker_id); } else { Snowflake::setWorkerId($server->worker_pid); $this->setWorkerAction($worker_id); } } - public function onSign() + + /** + * @param Server $server + * @param int $workerId + * 异步任务管制 + */ + public function onTaskSignal(Server $server, int $workerId) { Coroutine::getContext()['isComplete'] = false; - go(function () { + go(function () use ($server, $workerId) { $sigkill = Coroutine::waitSignal(SIGTERM | SIGKILL | SIGUSR2, -1); - var_dump($sigkill); if ($sigkill === false) { - return; + return $server->stop($workerId); } while (true) { $context = Coroutine::getContext(Coroutine::getPcid()); @@ -66,6 +75,7 @@ class OnWorkerStart extends Callback break; } } + return $server->stop($workerId); }); }