-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfog_server.py
91 lines (77 loc) · 2.73 KB
/
fog_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import logging
logger = logging.getLogger('ComfyFog')
from . import fog_manager
def fog_status(req):
"""
获取Fog节点当前状态
请求方式:GET /fog/status
Returns:
{
"status": {
"enabled": bool, # 是否启用
"connected": bool, # 是否连接到任务中心
"scheduler_active": bool, # 调度器是否活跃
"current_task": { # 当前任务信息,无任务时为null
"id": str, # 任务ID
"status": str, # 任务状态:processing/completed/failed
"started_at": str, # 开始时间,ISO格式
"progress": float # 进度,0-1
},
"schedule": [ # 调度时间段列表
{
"start": str, # 开始时间,格式 "HH:MM"
"end": str # 结束时间,格式 "HH:MM"
}
]
}
}
"""
try:
return {"status": fog_manager.get_status()}
except Exception as e:
logger.error(f"Error getting status: {e}")
return {"status": "error", "message": str(e)}
def fog_update_config(req):
"""
更新Fog节点配置
请求方式:POST /fog/config
请求体:
{
"enabled": bool, # 可选,是否启用
"task_center_url": str, # 可选,任务中心URL
"schedule": [ # 可选,调度时间段
{
"start": str, # 开始时间,格式 "HH:MM"
"end": str # 结束时间,格式 "HH:MM"
}
],
"max_tasks_per_day": int, # 可选,每日最大任务数
"min_gpu_memory": int, # 可选,最小GPU内存要求(MB)
"retry_interval": int, # 可选,重试间隔(秒)
"max_retries": int # 可选,最大重试次数
}
Returns:
成功:
{
"status": "success"
}
失败:
{
"status": "error",
"message": str # 错误信息
}
"""
try:
if not req.json:
raise ValueError("Request body is empty")
return fog_manager.update_config(req.json)
except Exception as e:
logger.error(f"Error updating config: {e}")
return {"status": "error", "message": str(e)}
# ComfyUI路由定义
ROUTES = [
("fog/status", fog_status), # GET 获取状态
("fog/config", fog_update_config, ["POST"]), # POST 更新配置
]
# 导出必要的变量
__all__ = ['ROUTES']