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