Updated monitor method for Supervisor.php to allow for a non-blocking method.

This commit is contained in:
Netkas 2023-03-01 18:55:30 -05:00
parent 9f822a494f
commit 3934a010d6
3 changed files with 13 additions and 5 deletions

View file

@ -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": {

View file

@ -148,11 +148,12 @@
/**
* 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)
{
@ -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);
}
}

View file

@ -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
{