From dcded7307f3466c7ab2bf5080d963c793ff16c24 Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 7 Dec 2023 18:20:46 +0300 Subject: [PATCH] docker features 2 --- ext/python-docker-client/dockerclient.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/python-docker-client/dockerclient.py b/ext/python-docker-client/dockerclient.py index f9ab74c..7c6082d 100644 --- a/ext/python-docker-client/dockerclient.py +++ b/ext/python-docker-client/dockerclient.py @@ -65,8 +65,6 @@ class Client: s = await c.stats(stream=False) s = s[0] - print(s) - cpu_delta = s['cpu_stats']['cpu_usage']['total_usage'] - s['precpu_stats']['cpu_usage']['total_usage'] system_cpu_delta = s['cpu_stats']['system_cpu_usage'] - s['precpu_stats']['system_cpu_usage'] @@ -110,12 +108,20 @@ if __name__ == "__main__": loop = asyncio.get_event_loop() print("Pre setup stage, get servers list...") - loop.run_until_complete(c.request_srvs()) - if c.servers.__len__() == 0: - print("Backent not respond, or server list not setup! Exit after 5 seconds...") - loop.run_until_complete(asyncio.sleep(5)) + + try_count = 5 + + while try_count: + try_count -= 1 + loop.run_until_complete(c.request_srvs()) + if c.servers.__len__() == 0: + print("Backend not respond, or server list not setup! Try again after 5 seconds...") + loop.run_until_complete(asyncio.sleep(5)) + + if try_count == 0: + print("Exit cannot get backend") sys.exit(1) - else: - print(f"Found {c.servers.__len__()} servers!") + + print(f"Found {c.servers.__len__()} servers!") loop.run_until_complete(c.loop(int(os.getenv("TIMEOUT", "5")))) \ No newline at end of file