弃用mq 采用回调接口方式

This commit is contained in:
zcr
2026-04-02 11:55:01 +08:00
parent 702f48626f
commit e40048bf5d
2 changed files with 20 additions and 20 deletions

View File

@@ -4,14 +4,14 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def notify_callback(callback_url: str, job_id: str, status: str, result: dict, ): async def notify_callback(callback_url: str, task_id: str, status: str, result: dict, ):
""" """
调用客户端提供的回调接口 调用客户端提供的回调接口
""" """
try: try:
payload = { payload = {
"job_id": job_id, "task_id": task_id,
" ": status, "status": status,
"result": result "result": result
} }
logger.info(payload) logger.info(payload)
@@ -23,12 +23,12 @@ async def notify_callback(callback_url: str, job_id: str, status: str, result: d
) )
if resp.status_code >= 200 and resp.status_code < 300: if resp.status_code >= 200 and resp.status_code < 300:
logger.info(f"回调成功 | job_id: {job_id} | status: {status} | url: {callback_url}") logger.info(f"回调成功 | task_id: {task_id} | status: {status} | url: {callback_url}")
return True return True
else: else:
logger.warning(f"回调返回非2xx状态码 | job_id: {job_id} | status: {resp.status_code} | url: {callback_url}") logger.warning(f"回调返回非2xx状态码 | task_id: {task_id} | status: {resp.status_code} | url: {callback_url}")
return False return False
except Exception as e: except Exception as e:
logger.error(f"回调失败 | job_id: {job_id} | url: {callback_url} | error: {e}", exc_info=True) logger.error(f"回调失败 | task_id: {task_id} | url: {callback_url} | error: {e}", exc_info=True)
return False return False

View File

@@ -13,8 +13,8 @@ logger = logging.getLogger(__name__)
@shared_task(bind=True, queue="img_to_3d_queue", max_retries=3, name='src.server.canvas_generate_3D.tasks.img_to_3d_task') @shared_task(bind=True, queue="img_to_3d_queue", max_retries=3, name='src.server.canvas_generate_3D.tasks.img_to_3d_task')
def img_to_3d_task(self, input_images: list, model: str = "single", callback_url: str = None): def img_to_3d_task(self, input_images: list, model: str = "single", callback_url: str = None):
"""img_to_3D 主任务""" """img_to_3D 主任务"""
job_id = self.request.id task_id = self.request.id
logger.info(f"开始处理 img_to_3D 任务 | job_id: {job_id}") logger.info(f"开始处理 img_to_3D 任务 | task_id: {task_id}")
try: try:
input_data = { input_data = {
"image_paths": input_images, "image_paths": input_images,
@@ -27,13 +27,13 @@ def img_to_3d_task(self, input_images: list, model: str = "single", callback_url
) )
status_code = resp.status_code status_code = resp.status_code
result = resp.json() result = resp.json()
logger.info(f"img_to_3D 任务处理完成 | job_id: {job_id} | status_code : {status_code} | result: {result}") logger.info(f"img_to_3D 任务处理完成 | task_id: {task_id} | status_code : {status_code} | result: {result}")
# 发送到对应的回调接口 # 发送到对应的回调接口
if status_code == 200: if status_code == 200:
asyncio.run( asyncio.run(
notify_callback( notify_callback(
callback_url=callback_url, callback_url=callback_url,
job_id=job_id, task_id=task_id,
status="completed", status="completed",
result=result, result=result,
) )
@@ -42,7 +42,7 @@ def img_to_3d_task(self, input_images: list, model: str = "single", callback_url
asyncio.run( asyncio.run(
notify_callback( notify_callback(
callback_url=callback_url, callback_url=callback_url,
job_id=job_id, task_id=task_id,
status="failed", status="failed",
result={}, result={},
) )
@@ -50,11 +50,11 @@ def img_to_3d_task(self, input_images: list, model: str = "single", callback_url
return result return result
except Exception as exc: except Exception as exc:
logger.error(f"img_to_3D 任务失败 | job_id: {job_id} | exc {exc}", exc_info=True) logger.error(f"img_to_3D 任务失败 | task_id: {task_id} | exc {exc}", exc_info=True)
asyncio.run( asyncio.run(
notify_callback( notify_callback(
callback_url=callback_url, callback_url=callback_url,
job_id=job_id, task_id=task_id,
status="failed", status="failed",
result=result, result=result,
) )
@@ -65,8 +65,8 @@ def img_to_3d_task(self, input_images: list, model: str = "single", callback_url
@shared_task(bind=True, queue="three_d_to_3views_queue", max_retries=3, name='src.server.canvas_generate_3D.tasks.three_d_to_3views_task') @shared_task(bind=True, queue="three_d_to_3views_queue", max_retries=3, name='src.server.canvas_generate_3D.tasks.three_d_to_3views_task')
def three_d_to_3views_task(self, minio_glb_path: str, callback_url: str): def three_d_to_3views_task(self, minio_glb_path: str, callback_url: str):
"""3D to 3views 主任务""" """3D to 3views 主任务"""
job_id = self.request.id task_id = self.request.id
logger.info(f"开始处理 three_d_to_3views_task | job_id: {job_id}") logger.info(f"开始处理 three_d_to_3views_task | task_id: {task_id}")
try: try:
input_data = { input_data = {
"minio_glb_path": minio_glb_path, "minio_glb_path": minio_glb_path,
@@ -78,13 +78,13 @@ def three_d_to_3views_task(self, minio_glb_path: str, callback_url: str):
) )
status_code = resp.status_code status_code = resp.status_code
result = resp.json() result = resp.json()
logger.info(f"three_d_to_3views_task 任务处理完成 | job_id: {job_id} | status_code : {status_code} | result: {result}") logger.info(f"three_d_to_3views_task 任务处理完成 | task_id: {task_id} | status_code : {status_code} | result: {result}")
# 发送到对应的回调接口 # 发送到对应的回调接口
if status_code == 200: if status_code == 200:
asyncio.run( asyncio.run(
notify_callback( notify_callback(
callback_url=callback_url, callback_url=callback_url,
job_id=job_id, task_id=task_id,
status="completed", status="completed",
result=result, result=result,
) )
@@ -93,7 +93,7 @@ def three_d_to_3views_task(self, minio_glb_path: str, callback_url: str):
asyncio.run( asyncio.run(
notify_callback( notify_callback(
callback_url=callback_url, callback_url=callback_url,
job_id=job_id, task_id=task_id,
status="failed", status="failed",
result={}, result={},
) )
@@ -101,11 +101,11 @@ def three_d_to_3views_task(self, minio_glb_path: str, callback_url: str):
return result return result
except Exception as exc: except Exception as exc:
logger.error(f"three_d_to_3views_task 任务失败 | job_id: {job_id}", exc_info=True) logger.error(f"three_d_to_3views_task 任务失败 | task_id: {task_id}", exc_info=True)
asyncio.run( asyncio.run(
notify_callback( notify_callback(
callback_url=callback_url, callback_url=callback_url,
job_id=job_id, task_id=task_id,
status="failed", status="failed",
result={}, result={},
) )