From 9da59299e37fe5ed3c4dab00ff866f7e40dde214 Mon Sep 17 00:00:00 2001 From: Thibault Dethier Date: Fri, 18 Oct 2024 11:17:17 +0200 Subject: [PATCH] [IA-3572] Setuper error after worker timeout --- setuper/iaso_api_client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setuper/iaso_api_client.py b/setuper/iaso_api_client.py index 96e5f5c903..7958bb56e0 100644 --- a/setuper/iaso_api_client.py +++ b/setuper/iaso_api_client.py @@ -3,6 +3,9 @@ class IasoClient: + ASYNC_TASK_TIMEOUT = 120 + ASYNC_TASK_WAIT_STEP = 5 + def __init__(self, server_url): self.debug = False self.server_url = server_url @@ -74,15 +77,18 @@ def wait_task_completion(self, task_to_wait): print(f"\tWaiting for async task '{task_to_wait['task']['name']}'") count = 0 imported = False - while not imported and count < 120: + while not imported and count < self.ASYNC_TASK_TIMEOUT: task = self.get(f"/api/tasks/{task_to_wait['task']['id']}") imported = task["status"] == "SUCCESS" if task["status"] == "ERRORED": raise Exception(f"Task failed {task}") - time.sleep(2) - count += 5 + time.sleep(self.ASYNC_TASK_WAIT_STEP) + count += self.ASYNC_TASK_WAIT_STEP print("\t\tWaiting:", count, "s elapsed", task.get("progress_message")) + raise Exception( + f"Couldn't find an available worker after {self.ASYNC_TASK_TIMEOUT} seconds. Please make sure a worker is running." + ) def log(self, arg1, arg2=None): if self.debug: