feat(workflow): enhance workflow execution and context management

This commit is contained in:
jxxghp
2026-06-04 14:10:06 +08:00
parent fd280a49b7
commit 9056caae40
10 changed files with 483 additions and 119 deletions

View File

@@ -26,6 +26,8 @@ class BaseAction(ABC):
def __init__(self, action_id: str):
self._action_id = action_id
self._done_flag = False
self._message = ""
self.systemconfigoper = SystemConfigOper()
@classmethod
@@ -92,9 +94,12 @@ class BaseAction(ABC):
workflow_cache = self.systemconfigoper.get(workflow_key) or {}
action_cache = workflow_cache.get(self._action_id) or []
if isinstance(data, list):
action_cache.extend(data)
for item in data:
if item not in action_cache:
action_cache.append(item)
else:
action_cache.append(data)
if data not in action_cache:
action_cache.append(data)
workflow_cache[self._action_id] = action_cache
self.systemconfigoper.set(workflow_key, workflow_cache)

View File

@@ -43,12 +43,19 @@ class FetchDownloadsAction(BaseAction):
"""
更新downloads中的下载任务状态
"""
__all_complete = False
self._downloads = context.downloads or []
if not self._downloads:
self.job_done("无下载任务")
return context
for download in self._downloads:
if global_vars.is_workflow_stopped(workflow_id):
break
logger.info(f"获取下载任务 {download.download_id} 状态 ...")
torrents = ActionChain().list_torrents(hashs=[download.download_id])
torrents = ActionChain().list_torrents(
hashs=[download.download_id],
downloader=download.downloader,
)
if not torrents:
download.completed = True
continue
@@ -61,5 +68,5 @@ class FetchDownloadsAction(BaseAction):
logger.info(f"下载任务 {download.download_id} 未完成")
download.completed = False
if all([d.completed for d in self._downloads]):
self.job_done()
self.job_done("下载任务已全部完成")
return context

View File

@@ -61,18 +61,18 @@ class ScrapeFileAction(BaseAction):
logger.info(f"{fileitem.path} 已刮削过,跳过")
continue
mediachain = MediaChain()
context = mediachain.recognize_by_path(
media_context = mediachain.recognize_by_path(
fileitem.path,
obtain_images=True,
)
if not context or not context.media_info:
if not media_context or not media_context.media_info:
_failed_count += 1
logger.info(f"{fileitem.path} 未识别到媒体信息,无法刮削")
continue
mediachain.scrape_metadata(
fileitem=fileitem,
meta=context.meta_info,
mediainfo=context.media_info
meta=media_context.meta_info,
mediainfo=media_context.media_info
)
self._scraped_files.append(fileitem)
# 保存缓存