crabbly commited on
Commit
bffefa0
·
1 Parent(s): 0b29256

Fix scheduling

Browse files
Files changed (1) hide show
  1. main.py +21 -0
main.py CHANGED
@@ -201,6 +201,27 @@ async def proxy_batch_stage(payload: dict = Body(...)):
201
  return {"success": False, "message": f"Proxy Error (Internal): {str(e)}", "rows": []}
202
 
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  @app.get("/proxy_preview/{session_id}/{row_id}/{preview_type}")
205
  async def proxy_preview(session_id: str, row_id: str, preview_type: str, username: str = Query(""), size: str = Query("thumb")):
206
  base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL
 
201
  return {"success": False, "message": f"Proxy Error (Internal): {str(e)}", "rows": []}
202
 
203
 
204
+ @app.post("/proxy_flush_queue")
205
+ async def proxy_flush_queue(payload: dict = Body(...)):
206
+ username = str(payload.get("username", ""))
207
+ if username.strip().lower() != "devtest":
208
+ return {"success": False, "message": "Queue flush is only available for devtest."}
209
+ target_url = f"{DEV_URL}/flush_queue"
210
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
211
+
212
+ def make_post():
213
+ return requests.post(target_url, headers=headers, json=payload, timeout=20)
214
+
215
+ try:
216
+ response = await run_in_threadpool(make_post)
217
+ response.raise_for_status()
218
+ return response.json()
219
+ except requests.exceptions.RequestException as e:
220
+ return proxy_error_payload("Proxy Error (Hugging Face)", e)
221
+ except Exception as e:
222
+ return {"success": False, "message": f"Proxy Error (Internal): {str(e)}"}
223
+
224
+
225
  @app.get("/proxy_preview/{session_id}/{row_id}/{preview_type}")
226
  async def proxy_preview(session_id: str, row_id: str, preview_type: str, username: str = Query(""), size: str = Query("thumb")):
227
  base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL