From 94e307c6970b3003f7cef64a42895eaa22bf2494 Mon Sep 17 00:00:00 2001 From: "Christian R. Garcia" Date: Fri, 1 Dec 2023 16:22:19 -0800 Subject: [PATCH] Harden `t` init as networking issues can slow or break the ability to initialize said `t`. --- actors/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/actors/__init__.py b/actors/__init__.py index 05b32a5a..95e89832 100644 --- a/actors/__init__.py +++ b/actors/__init__.py @@ -1,4 +1,5 @@ import os +import time # Initialize as normal if this module is NOT called from a test container. # This allows us to not use flaskbase when calling codes.py @@ -11,8 +12,14 @@ logger = get_logger(__name__) Tenants = TenantCache() - try: - t = get_service_tapis_client(tenants=Tenants) - except Exception as e: - logger.error(f'Could not instantiate tapy service client. Exception: {e}') - raise e \ No newline at end of file + for _ in range(5): + try: + t = get_service_tapis_client(tenants=Tenants) + break # Exit the loop if t is successfully created + except Exception as e: + logger.error(f'Could not instantiate tapy service client. Exception: {e}') + time.sleep(2) # Delay for 2 seconds before the next attempt + else: + msg = 'Failed to create tapy service client after 10 attempts, networking?' + logger.error(msg) + raise RuntimeError(msg) \ No newline at end of file