feat: demucs status查询端点(读Redis)+ worker usage说明
This commit is contained in:
parent
6e9171020d
commit
5ec5301e6e
54
scripts/demucs-status.dspy
Normal file
54
scripts/demucs-status.dspy
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Demucs 任务状态查询
|
||||||
|
# 部署到: /data/ymq/demucs-service/app/api/demucs-status.dspy
|
||||||
|
# GET /demucs/api/demucs-status?task_id=xxx
|
||||||
|
import json
|
||||||
|
|
||||||
|
task_id = params_kw.task_id
|
||||||
|
if not task_id:
|
||||||
|
return {"error": "task_id is required"}
|
||||||
|
|
||||||
|
env = request._run_ns
|
||||||
|
longtasks = env.longtasks
|
||||||
|
|
||||||
|
# longtasks 内部通过 Redis 存储结果,key 格式: {queue_name}:result:{task_id}
|
||||||
|
import redis.asyncio as redis
|
||||||
|
r = redis.Redis(host='127.0.0.1', port=6379, db=0, decode_responses=True)
|
||||||
|
|
||||||
|
# 尝试获取结果
|
||||||
|
result_key = f"demucs:result:{task_id}"
|
||||||
|
raw = await r.get(result_key)
|
||||||
|
|
||||||
|
if raw:
|
||||||
|
data = json.loads(raw)
|
||||||
|
return {
|
||||||
|
"task_id": task_id,
|
||||||
|
"status": "SUCCEEDED",
|
||||||
|
"vocals_url": data.get("vocals_path", ""),
|
||||||
|
"accompaniment_url": data.get("accompaniment_path", ""),
|
||||||
|
"duration": data.get("duration", 0),
|
||||||
|
"usage": data.get("usage", {"次": 1}),
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查是否在队列中
|
||||||
|
queue_key = f"demucs:queue"
|
||||||
|
in_queue = await r.lrange(queue_key, 0, -1)
|
||||||
|
for item in in_queue:
|
||||||
|
try:
|
||||||
|
item_data = json.loads(item)
|
||||||
|
if item_data.get("task_id") == task_id:
|
||||||
|
return {"task_id": task_id, "status": "queued"}
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 检查是否在处理中
|
||||||
|
processing_key = f"demucs:processing"
|
||||||
|
processing = await r.get(processing_key)
|
||||||
|
if processing:
|
||||||
|
try:
|
||||||
|
proc_data = json.loads(processing)
|
||||||
|
if proc_data.get("task_id") == task_id:
|
||||||
|
return {"task_id": task_id, "status": "processing"}
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return {"task_id": task_id, "status": "not_found"}
|
||||||
Loading…
x
Reference in New Issue
Block a user