All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import logging
|
|
|
|
from app.service.sketch2garment.tasks import sketch_to_garment
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def submit_sketch_to_garment_task(model: str = "single", task_id: str = "", callback_url: str = "", bucket_name: str = "test", user_id: str = "123", input_image_path: str = ""):
|
|
"""提交 img_to_3D 任务(带队列长度限制)"""
|
|
queue_name = "img_to_3d_queue"
|
|
max_queue_length = 10
|
|
|
|
try:
|
|
# current_length = get_queue_length(queue_name)
|
|
|
|
# if current_length >= max_queue_length:
|
|
# return {
|
|
# "state": "queue_full",
|
|
# "message": "当前 3D 生成请求较多,请稍后重试。",
|
|
# "queue_length": current_length,
|
|
# "max_length": max_queue_length
|
|
# }
|
|
|
|
# 提交任务
|
|
task = sketch_to_garment.apply_async(
|
|
args=(task_id, callback_url, bucket_name, input_image_path, user_id, model),
|
|
task_id=task_id,
|
|
queue="sketch_to_garment_queue")
|
|
|
|
# logger.info(f"img_to_3d_task 已提交 | task_id: {task_id} | 当前队列长度: {current_length}")
|
|
|
|
return {
|
|
"state": "success",
|
|
"task_id": task_id,
|
|
"message": "任务已成功提交,正在后台处理...",
|
|
}
|
|
|
|
except Exception as e:
|
|
logger.error(f"提交 img_to_3d_task 失败: {e}", exc_info=True)
|
|
return {
|
|
"state": "fail",
|
|
"message": "提交失败,请稍后重试。",
|
|
"error": str(e)
|
|
}
|