Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- async_microservice.py +1 -27
async_microservice.py
CHANGED
|
@@ -252,33 +252,7 @@ async def async_ticket(ticket: Ticket):
|
|
| 252 |
ticket_id = str(uuid4())
|
| 253 |
await ticket_queue.put((ticket_id, ticket))
|
| 254 |
results_store[ticket_id] = {"status": "queued"}
|
| 255 |
-
|
| 256 |
-
# --- POLLING LOOP: check every 2 seconds (you can tune this) ---
|
| 257 |
-
for _ in range(5): # Try up to 5 times → total 10 seconds
|
| 258 |
-
await asyncio.sleep(2)
|
| 259 |
-
current_status = results_store.get(ticket_id, {}).get("status")
|
| 260 |
-
print(f"⏳ Polling... current status = {current_status}")
|
| 261 |
-
|
| 262 |
-
if current_status == "completed":
|
| 263 |
-
return {
|
| 264 |
-
"ticket_id": ticket_id,
|
| 265 |
-
"status": "completed",
|
| 266 |
-
"result": results_store[ticket_id]["result"]
|
| 267 |
-
}
|
| 268 |
-
elif current_status == "error":
|
| 269 |
-
return {
|
| 270 |
-
"ticket_id": ticket_id,
|
| 271 |
-
"status": "error",
|
| 272 |
-
"detail": results_store[ticket_id].get("detail", "Unknown error")
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
# If still not done after polling
|
| 276 |
-
return {
|
| 277 |
-
"ticket_id": ticket_id,
|
| 278 |
-
"status": "processing",
|
| 279 |
-
"message": "Still processing, please check /result/{ticket_id} later."
|
| 280 |
-
}
|
| 281 |
-
|
| 282 |
|
| 283 |
# Get ticket result
|
| 284 |
@app.get("/result/{ticket_id}")
|
|
|
|
| 252 |
ticket_id = str(uuid4())
|
| 253 |
await ticket_queue.put((ticket_id, ticket))
|
| 254 |
results_store[ticket_id] = {"status": "queued"}
|
| 255 |
+
return {"ticket_id": ticket_id, "status": "queued"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
# Get ticket result
|
| 258 |
@app.get("/result/{ticket_id}")
|