From d3ef6da34a2912ef993bd34b8697c923cde7b2fc Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Tue, 11 Oct 2022 23:27:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Abstracts/ProcessManager.php | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Abstracts/ProcessManager.php b/Abstracts/ProcessManager.php index 49e861c..30ca42a 100644 --- a/Abstracts/ProcessManager.php +++ b/Abstracts/ProcessManager.php @@ -73,13 +73,7 @@ class ProcessManager extends Component throw new Exception('Process(' . $custom->getName() . ') is exists.'); } $this->_process[$custom->getName()] = new Process(function (Process $process) use ($custom) { - set_env('environmental', Kiri::PROCESS); - $system = sprintf('[%s].Custom Process', Config::get('id', 'system-service')); - Kiri::getLogger()->alert($system . ' ' . $custom->getName() . ' start.'); - if (Kiri::getPlatform()->isLinux()) { - $process->name($system . '[' . $process->pid . '].' . $custom->getName()); - } - $custom->onSigterm()->process($process); + $this->extracted($custom, $process); }, $custom->getRedirectStdinAndStdout(), $custom->getPipeType(), @@ -106,13 +100,7 @@ class ProcessManager extends Component public function resolve(BaseProcess $customProcess): Closure { return static function (Process $process) use ($customProcess) { - set_env('environmental', Kiri::PROCESS); - $system = sprintf('[%s].Custom Process', Config::get('id', 'system-service')); - Kiri::getLogger()->alert($system . ' ' . $customProcess->getName() . ' start.'); - if (Kiri::getPlatform()->isLinux()) { - $process->name($system . '[' . $process->pid . '].' . $customProcess->getName()); - } - $customProcess->onSigterm()->process($process); + $this->extracted($customProcess, $process); }; } @@ -178,6 +166,23 @@ class ProcessManager extends Component $process = $this->_process[$name]; $process->write($message); } - - + + /** + * @param mixed $custom + * @param Process $process + * @return void + * @throws Kiri\Exception\ConfigException + */ + public function extracted(mixed $custom, Process $process): void + { + set_env('environmental', Kiri::PROCESS); + $system = sprintf('[%s].Custom Process', Config::get('id', 'system-service')); + Kiri::getLogger()->alert($system . ' ' . $custom->getName() . ' start.'); + if (Kiri::getPlatform()->isLinux()) { + $process->name($system . '[' . $process->pid . '].' . $custom->getName()); + } + $custom->onSigterm()->process($process); + } + + }