mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-12-02 09:17:46 +01:00
Fix critical bug in healthcheck. Use repeat instead of delay.
This commit is contained in:
parent
769d39afcd
commit
032349387f
@ -37,9 +37,11 @@ class HealthCheck
|
|||||||
static::$requestTimeout = (int) Config::getInstance()->get('health_check.timeout');
|
static::$requestTimeout = (int) Config::getInstance()->get('health_check.timeout');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Loop::delay(static::$checkInterval*1000, function() {
|
Loop::repeat(static::$checkInterval*1000, function() use($parentPid){
|
||||||
Logger::getInstance()->info('Start health check');
|
Logger::getInstance()->info('Start health check');
|
||||||
|
if (!self::isProcessAlive($parentPid)) {
|
||||||
|
throw new RuntimeException('Parent process died');
|
||||||
|
}
|
||||||
$sessions = yield from static::getSessionList();
|
$sessions = yield from static::getSessionList();
|
||||||
$sessionsForCheck = static::getLoggedInSessions($sessions);
|
$sessionsForCheck = static::getLoggedInSessions($sessions);
|
||||||
$promises = [];
|
$promises = [];
|
||||||
@ -54,10 +56,15 @@ class HealthCheck
|
|||||||
Loop::run();
|
Loop::run();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
Logger::getInstance()->error($e->getMessage());
|
Logger::getInstance()->error($e->getMessage());
|
||||||
Logger::getInstance()->critical('Health check failed. Killing parent process');
|
Logger::getInstance()->critical('Health check failed');
|
||||||
exec("kill -9 $parentPid");
|
if (self::isProcessAlive($parentPid)) {
|
||||||
|
Logger::getInstance()->critical('Killing parent process');
|
||||||
|
exec("kill -9 $parentPid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::getInstance()->critical('Health check process exit');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getSessionList()
|
private static function getSessionList()
|
||||||
@ -112,4 +119,10 @@ class HealthCheck
|
|||||||
return yield $response->getBody()->buffer();
|
return yield $response->getBody()->buffer();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function isProcessAlive(int $pid): bool
|
||||||
|
{
|
||||||
|
$result = exec("ps -p $pid | grep $pid");
|
||||||
|
return !empty($result);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user