Skip to content

Commit

Permalink
oops. removed some nested try/except/if weirdness
Browse files Browse the repository at this point in the history
  • Loading branch information
sstill88 committed Dec 20, 2024
1 parent ab93827 commit 30e874c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions cerulean_cloud/cloud_run_orchestrator/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,35 +170,34 @@ async def send_inference_request_and_handle_response(self, http_client, img_arra
max_retries = 2 # Total attempts including the first try
retry_delay = 5 # Delay in seconds between retries

e = None
for attempt in range(max_retries):
try:
res = await http_client.post(
self.url + "/predict", json=payload.dict(), timeout=None
)
if res.status_code == 200:
return InferenceResultStack(**res.json())
else:
self.logger.warning(
structured_log(
f"Attempt {attempt + 1}: Failed with status code {res.status_code}. Retrying...",
severity="WARNING",
scene_id=self.sceneid,
)
)
if attempt < max_retries - 1:
await asyncio.sleep(retry_delay) # Wait before retrying
return InferenceResultStack(**res.json())
except Exception as e:
if attempt < max_retries - 1:
self.logger.warning(
structured_log(
f"Inference failed; Attempt {attempt + 1}, retrying . . .",
f"Inference error; Attempt {attempt + 1}, retrying . . .",
severity="WARNING",
scene_id=self.sceneid,
exception=str(e),
)
)
await asyncio.sleep(retry_delay) # Wait before retrying

self.logger.error(
structured_log(
"Inference Failed",
severity="ERROR",
exception=str(e),
traceback=traceback.format_exc(),
)
)

# If all attempts fail, raise an exception
raise Exception(f"All inference attempts failed after {max_retries} retries.")

Expand Down

0 comments on commit 30e874c

Please sign in to comment.