Add Chinese comments for Temporal workflow flow
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
"""Temporal worker runner."""
|
||||
"""Temporal worker 启动入口。
|
||||
|
||||
可以把 worker 理解成 Temporal 的“执行器进程”:
|
||||
它负责监听 task queue,然后真正执行 workflow / activity。
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from contextlib import AsyncExitStack
|
||||
@@ -31,9 +35,18 @@ from app.workers.workflows.mid_end_pipeline import MidEndPipelineWorkflow
|
||||
|
||||
|
||||
def build_workers(client: Client) -> list[Worker]:
|
||||
"""Create the worker set needed for the task queues in this MVP."""
|
||||
"""创建本项目需要的 worker 集合。
|
||||
|
||||
这里按 task queue 拆 worker,目的是把不同类型的任务分开:
|
||||
- control: 流程控制、review、失败收尾
|
||||
- image-gen: tryon / scene
|
||||
- post-process: texture / face / fusion
|
||||
- qc: 质检
|
||||
- export: 导出
|
||||
"""
|
||||
|
||||
return [
|
||||
# control 队列负责 workflow 本体,以及少量“流程状态管理型” activity。
|
||||
Worker(
|
||||
client,
|
||||
task_queue=IMAGE_PIPELINE_CONTROL_TASK_QUEUE,
|
||||
@@ -45,11 +58,13 @@ def build_workers(client: Client) -> list[Worker]:
|
||||
mark_workflow_failed_activity,
|
||||
],
|
||||
),
|
||||
# image-gen 队列放生成类步骤,便于后续横向扩容。
|
||||
Worker(
|
||||
client,
|
||||
task_queue=IMAGE_PIPELINE_IMAGE_GEN_TASK_QUEUE,
|
||||
activities=[run_tryon_activity, run_scene_activity],
|
||||
),
|
||||
# post-process 队列放增强/融合类步骤。
|
||||
Worker(
|
||||
client,
|
||||
task_queue=IMAGE_PIPELINE_POST_PROCESS_TASK_QUEUE,
|
||||
@@ -69,16 +84,17 @@ def build_workers(client: Client) -> list[Worker]:
|
||||
|
||||
|
||||
async def run_workers() -> None:
|
||||
"""Start all Temporal workers and keep the process alive."""
|
||||
"""启动全部 worker,并保持进程常驻。"""
|
||||
|
||||
client = await get_temporal_client()
|
||||
workers = build_workers(client)
|
||||
async with AsyncExitStack() as stack:
|
||||
for worker in workers:
|
||||
# 逐个把 worker 注册到上下文里,退出时会自动优雅关闭。
|
||||
await stack.enter_async_context(worker)
|
||||
# 用一个永不触发的 Event 让进程保持存活。
|
||||
await asyncio.Event().wait()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(run_workers())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user