yetessam commited on
Commit
4e76bca
·
verified ·
1 Parent(s): 1b320e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -48,7 +48,7 @@ def initialize_agent(endpoint_uri: str):
48
  )
49
 
50
 
51
- def wake_up_endpoint(endpoint_uri, max_wait=30):
52
  """Poll the endpoint until it responds OK or timeout."""
53
 
54
  # Get token from environment variable or secrets store
@@ -60,22 +60,22 @@ def wake_up_endpoint(endpoint_uri, max_wait=30):
60
 
61
  while time.time() - start < max_wait:
62
  try:
63
- print("Pinging endpoint...")
64
- print(endpoint_uri)
65
- response = requests.post(endpoint_uri, json=payload, timeout=5)
66
 
67
  if response.ok:
68
- print("✅ Endpoint is awake.")
69
  return True
70
 
71
  # If it's a 503 or 504, it's likely still warming up
72
- print(f"Response: {response.status_code}, retrying...")
73
  except requests.exceptions.RequestException as e:
74
- print(f"Exception: {e}, retrying...")
75
 
76
  time.sleep(3) # fixed short backoff; can be exponential if needed
77
 
78
- print("❌ Timed out waiting for endpoint to wake up.")
79
  return False
80
 
81
  def main():
@@ -99,7 +99,7 @@ def main():
99
  ui.append(endpoint_uri)
100
 
101
  # Wake it up before health check
102
- wake_up_successful = wake_up_endpoint(endpoint_uri)
103
 
104
  if not wake_up_successful:
105
  ui.append("Warning: Could not wake up the endpoint. Continuing.")
 
48
  )
49
 
50
 
51
+ def wake_up_endpoint(endpoint_uri, ui, max_wait=30):
52
  """Poll the endpoint until it responds OK or timeout."""
53
 
54
  # Get token from environment variable or secrets store
 
60
 
61
  while time.time() - start < max_wait:
62
  try:
63
+ ui.append("Pinging endpoint...")
64
+ ui.append(endpoint_uri)
65
+ response = requests.post(endpoint_uri, headers=headers, json=payload, timeout=5)
66
 
67
  if response.ok:
68
+ ui.append("✅ Endpoint is awake.")
69
  return True
70
 
71
  # If it's a 503 or 504, it's likely still warming up
72
+ ui.append(f"Response: {response.status_code}, retrying...")
73
  except requests.exceptions.RequestException as e:
74
+ ui.append(f"Exception: {e}, retrying...")
75
 
76
  time.sleep(3) # fixed short backoff; can be exponential if needed
77
 
78
+ ui.append("❌ Timed out waiting for endpoint to wake up.")
79
  return False
80
 
81
  def main():
 
99
  ui.append(endpoint_uri)
100
 
101
  # Wake it up before health check
102
+ wake_up_successful = wake_up_endpoint(endpoint_uri, ui)
103
 
104
  if not wake_up_successful:
105
  ui.append("Warning: Could not wake up the endpoint. Continuing.")