You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Temporal SDK无法返回全部工作流执行实例,请求排查方案

解决Temporal Python客户端list_workflows()无法返回全部运行中工作流的问题

问题背景

日志显示ID为execute-flow-97bc4090-4cb4-4652-9841-7f01b8fda6f8的工作流中send_email活动执行失败(已重试23928次),但通过temporal_client.list_workflows()无法找到该工作流,且返回的运行中工作流总数仅为145,未达设置的分页上限1000。

可能的原因及解决方案

1. 未指定正确的工作流状态过滤器

默认情况下list_workflows()可能不会返回所有状态的工作流,需显式指定查询运行中/重试等待状态的工作流:

from temporalio.client import WorkflowExecutionFilter, WorkflowExecutionStatus
import asyncio

async def main():
    temporal_settings = TemporalSettings()
    temporal_client = await create_temporal_client(temporal_settings)

    workflow_handle = temporal_client.get_workflow_handle("execute-flow-97bc4090-4cb4-4652-9841-7f01b8fda6f8")
    print("Workflow id:", workflow_handle.id)

    # 指定包含运行中、暂停、重试等待状态的过滤器
    status_filter = WorkflowExecutionFilter(statuses=[
        WorkflowExecutionStatus.RUNNING,
        WorkflowExecutionStatus.PAUSED,
        WorkflowExecutionStatus.WAITING
    ])
    
    workflow_executions_count = 0
    found = False
    async for workflow_execution in temporal_client.list_workflows(filter=status_filter, page_size=1000):
        workflow_executions_count += 1
        if workflow_execution.id == workflow_handle.id:
            print("Workflow execution found")
            found = True
            break

    if not found:
        print("Workflow execution not found")
    print("Workflow executions count:", workflow_executions_count)

asyncio.run(main())

2. 命名空间不匹配

确认客户端连接的命名空间与目标工作流所在命名空间一致,若工作流在非默认命名空间,需在创建客户端时指定:

# 创建客户端时指定目标命名空间
temporal_client = await create_temporal_client(temporal_settings, namespace="your-target-namespace")

3. 分页迭代逻辑问题

确保完整遍历所有分页结果(即使单页数量未达上限,也要检查是否存在下一页):

async def main():
    temporal_settings = TemporalSettings()
    temporal_client = await create_temporal_client(temporal_settings)

    workflow_handle = temporal_client.get_workflow_handle("execute-flow-97bc4090-4cb4-4652-9841-7f01b8fda6f8")
    print("Workflow id:", workflow_handle.id)

    status_filter = WorkflowExecutionFilter(status=WorkflowExecutionStatus.RUNNING)
    paginator = temporal_client.list_workflows(filter=status_filter, page_size=1000)
    
    workflow_executions_count = 0
    found = False
    async for page in paginator:
        for workflow_execution in page:
            workflow_executions_count += 1
            if workflow_execution.id == workflow_handle.id:
                print("Workflow execution found")
                found = True
                break
        if found:
            break

    if not found:
        print("Workflow execution not found")
    print("Workflow executions count:", workflow_executions_count)

asyncio.run(main())

4. 服务端配置限制

检查Temporal服务端的history.visibility.batch_size等配置项,若服务端设置了过小的结果返回限制,即使客户端设置大page_size也无法获取更多数据,需调整服务端配置后重试。

内容的提问来源于stack exchange,提问作者Prosto_Oleg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 19:37:26