From 3934a010d642fb2804074c3effa9ce5b1c6472f8 Mon Sep 17 00:00:00 2001 From: Netkas Date: Wed, 1 Mar 2023 18:55:30 -0500 Subject: [PATCH] Updated monitor method for Supervisor.php to allow for a non-blocking method. --- project.json | 2 +- src/TamerLib/Classes/Supervisor.php | 11 +++++++++-- src/TamerLib/Tamer.php | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/project.json b/project.json index a94ad85..388e54e 100644 --- a/project.json +++ b/project.json @@ -22,7 +22,7 @@ "description": "TamerLib allows the execution of parallel tasks", "company": "Nosial", "copyright": "Copyright (c) 2022-2023 Nosial, All Rights Reserved", - "version": "1.0.1", + "version": "1.0.2", "uuid": "a365e7d6-a1c0-11ed-b7c7-b9654ed9efa5" }, "build": { diff --git a/src/TamerLib/Classes/Supervisor.php b/src/TamerLib/Classes/Supervisor.php index c8c51ee..5c5dabc 100644 --- a/src/TamerLib/Classes/Supervisor.php +++ b/src/TamerLib/Classes/Supervisor.php @@ -148,13 +148,14 @@ /** * Monitors all the workers and restarts them if they are not running * + * @param bool $blocking * @param bool $auto_restart * @return void * @throws Exception */ - public function monitor(bool $auto_restart = true): void + public function monitor(bool $blocking=false, bool $auto_restart=true): void { - while (true) + while(true) { /** @var WorkerInstance $worker */ foreach ($this->workers as $worker) @@ -163,6 +164,7 @@ { if ($auto_restart) { + Log::warning('net.nosial.tamerlib', "worker {$worker->getId()} is not running, restarting"); $worker->start(); } else @@ -172,6 +174,11 @@ } } + if (!$blocking) + { + break; + } + sleep(1); } } diff --git a/src/TamerLib/Tamer.php b/src/TamerLib/Tamer.php index 9f9c9b3..dbfd26b 100644 --- a/src/TamerLib/Tamer.php +++ b/src/TamerLib/Tamer.php @@ -314,15 +314,16 @@ /** * Monitors the workers and restarts them if they die unexpectedly (monitor mode only) * + * @param bool $blocking * @param bool $auto_restart * @return void * @throws Exception */ - public static function monitor(bool $auto_restart=false): void + public static function monitor(bool $blocking=false, bool $auto_restart=true): void { if (self::$mode === Mode::Client) { - self::$supervisor->monitor($auto_restart); + self::$supervisor->monitor($blocking, $auto_restart); } else {