Spaces:
Running
Running
AILIXIR Bot commited on
Commit ·
2d89783
1
Parent(s): 17620ec
Auto-sync: d2402d260057f3dc7305a96f1743f9d64c1d5f30
Browse files
.github/workflows/integration-test-hf.yml
CHANGED
|
@@ -387,35 +387,58 @@ jobs:
|
|
| 387 |
fi
|
| 388 |
|
| 389 |
python3 - <<'PY'
|
| 390 |
-
import json, sys
|
|
|
|
| 391 |
data = json.load(open("dr_targets.json"))
|
| 392 |
if not data.get("success"):
|
| 393 |
print("DR target lookup failed:", json.dumps(data, indent=2))
|
| 394 |
sys.exit(1)
|
|
|
|
| 395 |
job_id = data.get("data", {}).get("job_id")
|
| 396 |
status = data.get("data", {}).get("status")
|
| 397 |
print(f"DR target lookup OK - job_id={job_id}, status={status}")
|
| 398 |
|
| 399 |
-
# Poll for completion
|
| 400 |
-
import time, urllib.request
|
| 401 |
base = "https://Ailixir-AI-Team-ailixir-api.hf.space/api/drug-repurposing/targets"
|
| 402 |
with open("token.txt") as f: token = f.read().strip()
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
print("DR target lookup did not complete in time")
|
| 420 |
sys.exit(1)
|
| 421 |
PY
|
|
|
|
| 387 |
fi
|
| 388 |
|
| 389 |
python3 - <<'PY'
|
| 390 |
+
import json, sys, time, urllib.request
|
| 391 |
+
|
| 392 |
data = json.load(open("dr_targets.json"))
|
| 393 |
if not data.get("success"):
|
| 394 |
print("DR target lookup failed:", json.dumps(data, indent=2))
|
| 395 |
sys.exit(1)
|
| 396 |
+
|
| 397 |
job_id = data.get("data", {}).get("job_id")
|
| 398 |
status = data.get("data", {}).get("status")
|
| 399 |
print(f"DR target lookup OK - job_id={job_id}, status={status}")
|
| 400 |
|
| 401 |
+
# Poll for completion with exponential backoff
|
|
|
|
| 402 |
base = "https://Ailixir-AI-Team-ailixir-api.hf.space/api/drug-repurposing/targets"
|
| 403 |
with open("token.txt") as f: token = f.read().strip()
|
| 404 |
+
|
| 405 |
+
max_attempts = 30
|
| 406 |
+
backoff_base = 5 # Start with 5 second delay
|
| 407 |
+
retry_count = 0
|
| 408 |
+
max_retries = 3
|
| 409 |
+
|
| 410 |
+
for i in range(max_attempts):
|
| 411 |
+
try:
|
| 412 |
+
req = urllib.request.Request(f"{base}/{job_id}")
|
| 413 |
+
req.add_header("Authorization", f"Bearer {token}")
|
| 414 |
+
resp = urllib.request.urlopen(req)
|
| 415 |
+
status_data = json.loads(resp.read())
|
| 416 |
+
retry_count = 0 # Reset retry count on success
|
| 417 |
+
|
| 418 |
+
s = status_data.get("data", {}).get("status")
|
| 419 |
+
if s == "completed":
|
| 420 |
+
output = status_data.get("data", {}).get("output", {})
|
| 421 |
+
assert len(output.get("targets", [])) > 0, "No targets found"
|
| 422 |
+
print(f"DR targets completed - {len(output['targets'])} targets found")
|
| 423 |
+
sys.exit(0)
|
| 424 |
+
elif s == "failed":
|
| 425 |
+
print("DR target lookup failed:", json.dumps(status_data, indent=2))
|
| 426 |
+
sys.exit(1)
|
| 427 |
+
|
| 428 |
+
print(f" Polling... attempt {i+1}/{max_attempts}, status={s}")
|
| 429 |
+
time.sleep(backoff_base)
|
| 430 |
+
|
| 431 |
+
except urllib.error.HTTPError as e:
|
| 432 |
+
if e.code == 429 and retry_count < max_retries:
|
| 433 |
+
# Rate limited - exponential backoff
|
| 434 |
+
retry_count += 1
|
| 435 |
+
wait_time = backoff_base * (2 ** retry_count)
|
| 436 |
+
print(f" Rate limited (429). Retry {retry_count}/{max_retries}, waiting {wait_time}s...")
|
| 437 |
+
time.sleep(wait_time)
|
| 438 |
+
else:
|
| 439 |
+
print(f"HTTP Error {e.code}: {e.reason}")
|
| 440 |
+
sys.exit(1)
|
| 441 |
+
|
| 442 |
print("DR target lookup did not complete in time")
|
| 443 |
sys.exit(1)
|
| 444 |
PY
|