feat: 调度队列接口添加字段说明
This commit is contained in:
@@ -34,7 +34,8 @@ router = APIRouter(prefix="/api/queue", tags=["调度队列管理"])
|
||||
async def add_queue() -> QueueCreateOut:
|
||||
|
||||
uid, config = await Config.add_queue()
|
||||
return QueueCreateOut(queueId=str(uid), data=await config.toDict())
|
||||
data = QueueConfig(**(await config.toDict()))
|
||||
return QueueCreateOut(queueId=str(uid), data=data)
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -43,7 +44,9 @@ async def add_queue() -> QueueCreateOut:
|
||||
async def get_queues(queue: QueueGetIn = Body(...)) -> QueueGetOut:
|
||||
|
||||
try:
|
||||
index, data = await Config.get_queue(queue.queueId)
|
||||
index, config = await Config.get_queue(queue.queueId)
|
||||
index = [QueueIndexItem(**_) for _ in index]
|
||||
data = {uid: QueueConfig(**cfg) for uid, cfg in config.items()}
|
||||
except Exception as e:
|
||||
return QueueGetOut(code=500, status="error", message=str(e), index=[], data={})
|
||||
return QueueGetOut(index=index, data=data)
|
||||
@@ -55,7 +58,9 @@ async def get_queues(queue: QueueGetIn = Body(...)) -> QueueGetOut:
|
||||
async def update_queue(queue: QueueUpdateIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.update_queue(queue.queueId, queue.data)
|
||||
await Config.update_queue(
|
||||
queue.queueId, queue.data.model_dump(exclude_unset=True)
|
||||
)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
@@ -87,7 +92,8 @@ async def reorder_queue(script: QueueReorderIn = Body(...)) -> OutBase:
|
||||
async def add_time_set(time: QueueSetInBase = Body(...)) -> TimeSetCreateOut:
|
||||
|
||||
uid, config = await Config.add_time_set(time.queueId)
|
||||
return TimeSetCreateOut(timeSetId=str(uid), data=await config.toDict())
|
||||
data = TimeSet(**(await config.toDict()))
|
||||
return TimeSetCreateOut(timeSetId=str(uid), data=data)
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -96,7 +102,9 @@ async def add_time_set(time: QueueSetInBase = Body(...)) -> TimeSetCreateOut:
|
||||
async def update_time_set(time: TimeSetUpdateIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.update_time_set(time.queueId, time.timeSetId, time.data)
|
||||
await Config.update_time_set(
|
||||
time.queueId, time.timeSetId, time.data.model_dump(exclude_unset=True)
|
||||
)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
@@ -135,7 +143,8 @@ async def reorder_time_set(time: TimeSetReorderIn = Body(...)) -> OutBase:
|
||||
async def add_item(item: QueueSetInBase = Body(...)) -> QueueItemCreateOut:
|
||||
|
||||
uid, config = await Config.add_queue_item(item.queueId)
|
||||
return QueueItemCreateOut(queueItemId=str(uid), data=await config.toDict())
|
||||
data = QueueItem(**(await config.toDict()))
|
||||
return QueueItemCreateOut(queueItemId=str(uid), data=data)
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -144,7 +153,9 @@ async def add_item(item: QueueSetInBase = Body(...)) -> QueueItemCreateOut:
|
||||
async def update_item(item: QueueItemUpdateIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.update_queue_item(item.queueId, item.queueItemId, item.data)
|
||||
await Config.update_queue_item(
|
||||
item.queueId, item.queueItemId, item.data.model_dump(exclude_unset=True)
|
||||
)
|
||||
except Exception as e:
|
||||
return OutBase(code=500, status="error", message=str(e))
|
||||
return OutBase()
|
||||
|
||||
@@ -243,13 +243,6 @@ class QueueConfig(ConfigBase):
|
||||
),
|
||||
)
|
||||
|
||||
self.Data_LastProxyTime = ConfigItem(
|
||||
"Data", "LastProxyTime", "2000-01-01 00:00:00"
|
||||
)
|
||||
self.Data_LastProxyHistory = ConfigItem(
|
||||
"Data", "LastProxyHistory", "暂无历史运行记录"
|
||||
)
|
||||
|
||||
self.TimeSet = MultipleConfig([TimeSet])
|
||||
self.QueueItem = MultipleConfig([QueueItem])
|
||||
|
||||
@@ -820,6 +813,8 @@ class AppConfig(GlobalConfig):
|
||||
else:
|
||||
data = await self.QueueConfig.get(uuid.UUID(queue_id))
|
||||
|
||||
print(data)
|
||||
|
||||
index = data.pop("instances", [])
|
||||
|
||||
return list(index), data
|
||||
@@ -971,6 +966,7 @@ class AppConfig(GlobalConfig):
|
||||
if isinstance(queue_config, QueueConfig):
|
||||
uid, config = await queue_config.QueueItem.add(QueueItem)
|
||||
else:
|
||||
logger.warning(f"Unsupported script config type: {type(queue_config)}")
|
||||
raise TypeError(f"Unsupported script config type: {type(queue_config)}")
|
||||
|
||||
await self.QueueConfig.save()
|
||||
@@ -989,6 +985,7 @@ class AppConfig(GlobalConfig):
|
||||
for group, items in data.items():
|
||||
for name, value in items.items():
|
||||
if uuid.UUID(value) not in self.ScriptConfig:
|
||||
logger.warning(f"Script with uid {value} does not exist.")
|
||||
raise ValueError(f"Script with uid {value} does not exist.")
|
||||
logger.debug(f"更新队列项配置:{queue_id} - {group}.{name} = {value}")
|
||||
if isinstance(queue_config, QueueConfig):
|
||||
@@ -1269,7 +1266,7 @@ class AppConfig(GlobalConfig):
|
||||
for uid, script in self.ScriptConfig.items():
|
||||
data.append(
|
||||
{
|
||||
"label": f"{TYPE_BOOK[script.__class__.__name__]} - {script.get('Info', 'Name')}",
|
||||
"label": f"{TYPE_BOOK[type(script).__name__]} - {script.get('Info', 'Name')}",
|
||||
"value": str(uid),
|
||||
}
|
||||
)
|
||||
@@ -1292,7 +1289,7 @@ class AppConfig(GlobalConfig):
|
||||
for uid, script in self.ScriptConfig.items():
|
||||
data.append(
|
||||
{
|
||||
"label": f"脚本 - {TYPE_BOOK[script.__class__.__name__]} - {script.get('Info', 'Name')}",
|
||||
"label": f"脚本 - {TYPE_BOOK[type(script).__name__]} - {script.get('Info', 'Name')}",
|
||||
"value": str(uid),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -122,7 +122,7 @@ class _TaskManager:
|
||||
task_item = GeneralManager(mode, task_id, actual_id, websocket)
|
||||
else:
|
||||
logger.error(
|
||||
f"不支持的脚本类型:{Config.ScriptConfig[task_id].__class__.__name__}"
|
||||
f"不支持的脚本类型:{type(Config.ScriptConfig[task_id]).__name__}"
|
||||
)
|
||||
await websocket.send_json(
|
||||
TaskMessage(
|
||||
@@ -146,7 +146,7 @@ class _TaskManager:
|
||||
queue = Config.QueueConfig[task_id]
|
||||
if not isinstance(queue, QueueConfig):
|
||||
logger.error(
|
||||
f"不支持的队列类型:{Config.QueueConfig[task_id].__class__.__name__}"
|
||||
f"不支持的队列类型:{type(Config.QueueConfig[task_id]).__name__}"
|
||||
)
|
||||
await websocket.send_json(
|
||||
TaskMessage(
|
||||
@@ -203,7 +203,7 @@ class _TaskManager:
|
||||
task_item = GeneralManager(mode, task_id, actual_id, websocket)
|
||||
else:
|
||||
logger.error(
|
||||
f"不支持的脚本类型:{Config.ScriptConfig[script_id].__class__.__name__}"
|
||||
f"不支持的脚本类型:{type(Config.ScriptConfig[script_id]).__name__}"
|
||||
)
|
||||
await websocket.send_json(
|
||||
TaskMessage(
|
||||
|
||||
@@ -591,8 +591,7 @@ class MultipleConfig:
|
||||
|
||||
data: Dict[str, Union[list, dict]] = {
|
||||
"instances": [
|
||||
{"uid": str(_), "type": self.data[_].__class__.__name__}
|
||||
for _ in self.order
|
||||
{"uid": str(_), "type": type(self.data[_]).__name__} for _ in self.order
|
||||
]
|
||||
}
|
||||
for uid, config in self.items():
|
||||
@@ -618,7 +617,7 @@ class MultipleConfig:
|
||||
|
||||
data: Dict[str, Union[list, dict]] = {
|
||||
"instances": [
|
||||
{"uid": str(_), "type": self.data[_].__class__.__name__}
|
||||
{"uid": str(_), "type": type(self.data[_]).__name__}
|
||||
for _ in self.order
|
||||
if _ == uid
|
||||
]
|
||||
|
||||
@@ -133,63 +133,44 @@ class GlobalConfig(BaseModel):
|
||||
Update: Optional[GlobalConfig_Update] = Field(None, description="更新相关配置")
|
||||
|
||||
|
||||
# class QueueItem(ConfigBase):
|
||||
# """队列项配置"""
|
||||
|
||||
# def __init__(self) -> None:
|
||||
# super().__init__()
|
||||
|
||||
# self.Info_ScriptId = ConfigItem("Info", "ScriptId", None, UidValidator())
|
||||
class QueueItem_Info(BaseModel):
|
||||
ScriptId: Optional[str] = Field(
|
||||
None, description="任务所对应的脚本ID, 为None时表示未选择"
|
||||
)
|
||||
|
||||
|
||||
# class TimeSet(ConfigBase):
|
||||
# """时间设置配置"""
|
||||
|
||||
# def __init__(self) -> None:
|
||||
# super().__init__()
|
||||
|
||||
# self.Info_Enabled = ConfigItem("Info", "Enabled", False, BoolValidator())
|
||||
# self.Info_Time = ConfigItem("Info", "Time", "00:00")
|
||||
class QueueItem(BaseModel):
|
||||
Info: Optional[QueueItem_Info] = Field(None, description="队列项")
|
||||
|
||||
|
||||
# class QueueConfig(ConfigBase):
|
||||
# """队列配置"""
|
||||
class TimeSet_Info(BaseModel):
|
||||
Enabled: Optional[bool] = Field(None, description="是否启用")
|
||||
Time: Optional[str] = Field(None, description="时间设置, 格式为HH:MM")
|
||||
|
||||
# def __init__(self) -> None:
|
||||
# super().__init__()
|
||||
|
||||
# self.Info_Name = ConfigItem("Info", "Name", "")
|
||||
# self.Info_TimeEnabled = ConfigItem(
|
||||
# "Info", "TimeEnabled", False, BoolValidator()
|
||||
# )
|
||||
# self.Info_StartUpEnabled = ConfigItem(
|
||||
# "Info", "StartUpEnabled", False, BoolValidator()
|
||||
# )
|
||||
# self.Info_AfterAccomplish = ConfigItem(
|
||||
# "Info",
|
||||
# "AfterAccomplish",
|
||||
# "NoAction",
|
||||
# OptionsValidator(
|
||||
# [
|
||||
# "NoAction",
|
||||
# "KillSelf",
|
||||
# "Sleep",
|
||||
# "Hibernate",
|
||||
# "Shutdown",
|
||||
# "ShutdownForce",
|
||||
# ]
|
||||
# ),
|
||||
# )
|
||||
class TimeSet(BaseModel):
|
||||
Info: Optional[TimeSet_Info] = Field(None, description="时间项")
|
||||
|
||||
# self.Data_LastProxyTime = ConfigItem(
|
||||
# "Data", "LastProxyTime", "2000-01-01 00:00:00"
|
||||
# )
|
||||
# self.Data_LastProxyHistory = ConfigItem(
|
||||
# "Data", "LastProxyHistory", "暂无历史运行记录"
|
||||
# )
|
||||
|
||||
# self.TimeSet = MultipleConfig([TimeSet])
|
||||
# self.QueueItem = MultipleConfig([QueueItem])
|
||||
class QueueIndexItem(BaseModel):
|
||||
uid: str = Field(..., description="唯一标识符")
|
||||
type: Literal["QueueConfig"] = Field(..., description="配置类型")
|
||||
|
||||
|
||||
class QueueConfig_Info(BaseModel):
|
||||
Name: Optional[str] = Field(None, description="队列名称")
|
||||
TimeEnabled: Optional[bool] = Field(None, description="是否启用定时")
|
||||
StartUpEnabled: Optional[bool] = Field(None, description="是否启动时运行")
|
||||
AfterAccomplish: Optional[
|
||||
Literal[
|
||||
"NoAction", "KillSelf", "Sleep", "Hibernate", "Shutdown", "ShutdownForce"
|
||||
]
|
||||
] = Field(None, description="完成后操作")
|
||||
|
||||
|
||||
class QueueConfig(BaseModel):
|
||||
|
||||
Info: Optional[QueueConfig_Info] = Field(None, description="队列信息")
|
||||
|
||||
|
||||
# class MaaUserConfig(ConfigBase):
|
||||
@@ -652,21 +633,23 @@ class PlanReorderIn(BaseModel):
|
||||
|
||||
class QueueCreateOut(OutBase):
|
||||
queueId: str = Field(..., description="新创建的队列ID")
|
||||
data: Dict[str, Any] = Field(..., description="队列配置数据")
|
||||
data: QueueConfig = Field(..., description="队列配置数据")
|
||||
|
||||
|
||||
class QueueGetIn(BaseModel):
|
||||
queueId: Optional[str] = Field(None, description="队列ID,仅在模式为Single时需要")
|
||||
queueId: Optional[str] = Field(
|
||||
None, description="队列ID, 未携带时表示获取所有队列数据"
|
||||
)
|
||||
|
||||
|
||||
class QueueGetOut(OutBase):
|
||||
index: List[Dict[str, str]] = Field(..., description="队列索引列表")
|
||||
data: Dict[str, Any] = Field(..., description="队列列表或单个队列数据")
|
||||
index: List[QueueIndexItem] = Field(..., description="队列索引列表")
|
||||
data: Dict[str, QueueConfig] = Field(..., description="队列列表或单个队列数据")
|
||||
|
||||
|
||||
class QueueUpdateIn(BaseModel):
|
||||
queueId: str = Field(..., description="队列ID")
|
||||
data: Dict[str, Dict[str, Any]] = Field(..., description="队列更新数据")
|
||||
data: QueueConfig = Field(..., description="队列更新数据")
|
||||
|
||||
|
||||
class QueueDeleteIn(BaseModel):
|
||||
@@ -674,7 +657,7 @@ class QueueDeleteIn(BaseModel):
|
||||
|
||||
|
||||
class QueueReorderIn(BaseModel):
|
||||
indexList: List[str] = Field(..., description="调度队列ID列表,按新顺序排列")
|
||||
indexList: List[str] = Field(..., description="按新顺序排列的调度队列UID列表")
|
||||
|
||||
|
||||
class QueueSetInBase(BaseModel):
|
||||
@@ -683,12 +666,12 @@ class QueueSetInBase(BaseModel):
|
||||
|
||||
class TimeSetCreateOut(OutBase):
|
||||
timeSetId: str = Field(..., description="新创建的时间设置ID")
|
||||
data: Dict[str, Any] = Field(..., description="时间设置配置数据")
|
||||
data: TimeSet = Field(..., description="时间设置配置数据")
|
||||
|
||||
|
||||
class TimeSetUpdateIn(QueueSetInBase):
|
||||
timeSetId: str = Field(..., description="时间设置ID")
|
||||
data: Dict[str, Dict[str, Any]] = Field(..., description="时间设置更新数据")
|
||||
data: TimeSet = Field(..., description="时间设置更新数据")
|
||||
|
||||
|
||||
class TimeSetDeleteIn(QueueSetInBase):
|
||||
@@ -701,12 +684,12 @@ class TimeSetReorderIn(QueueSetInBase):
|
||||
|
||||
class QueueItemCreateOut(OutBase):
|
||||
queueItemId: str = Field(..., description="新创建的队列项ID")
|
||||
data: Dict[str, Any] = Field(..., description="队列项配置数据")
|
||||
data: QueueItem = Field(..., description="队列项配置数据")
|
||||
|
||||
|
||||
class QueueItemUpdateIn(QueueSetInBase):
|
||||
queueItemId: str = Field(..., description="队列项ID")
|
||||
data: Dict[str, Dict[str, Any]] = Field(..., description="队列项更新数据")
|
||||
data: QueueItem = Field(..., description="队列项更新数据")
|
||||
|
||||
|
||||
class QueueItemDeleteIn(QueueSetInBase):
|
||||
|
||||
Reference in New Issue
Block a user