|
|
@@ -38,21 +38,42 @@ async def execute_task(request: ExecuteRequest):
|
|
|
"""
|
|
|
接收Java端下发的解析任务,后台异步执行
|
|
|
"""
|
|
|
+ try:
|
|
|
+ # 验证请求参数
|
|
|
+ if not request.file_path or not request.task_id:
|
|
|
+ return {
|
|
|
+ "code": 400,
|
|
|
+ "msg": "参数错误:filePath和taskId不能为空",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
|
|
|
- # 调用远程解析服务
|
|
|
- remote_url = "http://10.192.72.13:1086/execute"
|
|
|
+ # 调用远程解析服务
|
|
|
+ remote_url = "http://localhost:1086/execute"
|
|
|
|
|
|
- async with httpx.AsyncClient() as client:
|
|
|
- response = await client.post(
|
|
|
- remote_url,
|
|
|
- json={
|
|
|
- "filePath": request.file_path,
|
|
|
- "taskId": request.task_id
|
|
|
- },
|
|
|
- timeout=300.0
|
|
|
- )
|
|
|
- response.raise_for_status()
|
|
|
- return response.json()
|
|
|
+ async with httpx.AsyncClient(timeout=300) as client:
|
|
|
+ try:
|
|
|
+ response = await client.post(
|
|
|
+ remote_url,
|
|
|
+ json={
|
|
|
+ "filePath": request.file_path,
|
|
|
+ "taskId": request.task_id
|
|
|
+ }
|
|
|
+ )
|
|
|
+ response.raise_for_status()
|
|
|
+ return response.json()
|
|
|
+ except Exception as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": f"调用远程解析服务失败: {str(e)}",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ return {
|
|
|
+ "code": 500,
|
|
|
+ "msg": f"服务内部错误: {str(e)}",
|
|
|
+ "data": None
|
|
|
+ }
|
|
|
|
|
|
@app.get("/status", summary="状态接口")
|
|
|
async def health_check():
|