All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import logging
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger("app")
|
|
|
|
|
|
async def notify_callback(callback_url: str, task_id: str, status: str, result: dict, ):
|
|
"""
|
|
调用客户端提供的回调接口
|
|
"""
|
|
try:
|
|
payload = {
|
|
"task_id": task_id,
|
|
"status": status,
|
|
"result": result
|
|
}
|
|
logger.info(payload)
|
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
resp = await client.post(
|
|
str(callback_url),
|
|
json=payload,
|
|
headers={"Content-Type": "application/json"}
|
|
)
|
|
|
|
if 200 <= resp.status_code < 300:
|
|
logger.info(f"回调成功 | task_id: {task_id} | status: {status} | url: {callback_url}")
|
|
return True
|
|
else:
|
|
logger.warning(f"回调返回非2xx状态码 | task_id: {task_id} | status: {resp.status_code} | url: {callback_url}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
logger.error(f"回调失败 | task_id: {task_id} | url: {callback_url} | error: {e}", exc_info=True)
|
|
return False
|