mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-11 09:59:51 +08:00
fix workflow
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from typing import Dict, Any
|
||||
from time import sleep
|
||||
from typing import Dict, Any, Tuple
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.helper.module import ModuleHelper
|
||||
from app.log import logger
|
||||
from app.schemas import Action, ActionContext
|
||||
from app.utils.singleton import Singleton
|
||||
|
||||
|
||||
@@ -30,6 +32,8 @@ class WorkFlowManager(metaclass=Singleton):
|
||||
return False
|
||||
if not hasattr(obj, 'execute') or not hasattr(obj, "name"):
|
||||
return False
|
||||
if obj.__name__ == "BaseAction":
|
||||
return False
|
||||
return obj.__module__.startswith("app.actions")
|
||||
|
||||
# 加载所有动作
|
||||
@@ -47,3 +51,27 @@ class WorkFlowManager(metaclass=Singleton):
|
||||
停止
|
||||
"""
|
||||
pass
|
||||
|
||||
def excute(self, action: Action, context: ActionContext = None) -> Tuple[bool, ActionContext]:
|
||||
"""
|
||||
执行工作流动作
|
||||
"""
|
||||
if not context:
|
||||
context = ActionContext()
|
||||
if action.id in self._actions:
|
||||
action_obj = self._actions[action.id]
|
||||
logger.info(f"执行动作: {action.id} - {action.name}")
|
||||
result_context = action_obj.execute(action.params, context)
|
||||
logger.info(f"{action.name} 执行结果: {action_obj.success}")
|
||||
if action.loop and action.loop_interval:
|
||||
while not action_obj.done:
|
||||
logger.info(f"{action.name} 等待 {action.loop_interval} 秒后继续执行")
|
||||
sleep(action.loop_interval)
|
||||
logger.info(f"继续执行动作: {action.id} - {action.name}")
|
||||
result_context = action_obj.execute(action.params, result_context)
|
||||
logger.info(f"{action.name} 执行结果: {action_obj.success}")
|
||||
logger.info(f"{action.name} 执行完成")
|
||||
return action_obj.success, result_context
|
||||
else:
|
||||
logger.error(f"未找到动作: {action.id} - {action.name}")
|
||||
return False, context
|
||||
|
||||
Reference in New Issue
Block a user