适用于 Amazon SWF 的 EventBridge 执行状态更改 - Amazon Simple Workflow Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

适用于 Amazon SWF 的 EventBridge 执行状态更改

您可以使用 Amazon EventBridge 来响应您 Amazon 资源中的状态更改或事件。当 Amazon SWF 发出事件时,它始终会发送到您账户默认的 EventBridge 事件总线。您可以为事件创建规则,将其与默认事件总线关联,并指定当 EventBridge 收到符合规则的事件时要执行的目标操作。这样一来,您可以监控您的工作流,而不必持续不断地使用 GetWorkflowExecutionHistory API 进行轮询。根据工作流执行中的更改,您可以使用 EventBridge 目标来调用 Amazon Lambda 函数,将消息发布到 Amazon Simple Notification Service (Amazon SNS) 主题,等等。

您可以使用 DescribeWorkflowExecution 查看执行状态更改事件的全部内容。

有关更多信息,请参阅 Amazon EventBridge 用户指南

EventBridge 事件

历史记录事件类型包含执行状态的更改。每个事件的 detail 部分至少包含以下参数:

  • eventId:GetWorkflowExecutionHistory 显示的事件 ID。

  • workflowExecutionDetail:发出事件时工作流的状态。

  • eventType:历史记录事件类型,以下任一类型:

    • ActivityTaskCanceled

    • ActivityTaskFailed

    • ActivityTaskTimedOut

    • WorkflowExecutionCanceled

    • WorkflowExecutionCompleted

    • WorkflowExecutionFailed

    • WorkflowExecutionStarted

    • WorkflowExecutionTerminated

    • WorkflowExecutionTimedOut

    • WorkflowExecutionContinuedAsNew

    • CancelTimerFailed

    • CancelWorkflowExecutionFailed

    • ChildWorkflowExecutionFailed

    • ChildWorkflowExecutionTimedOut

    • CompleteWorkflowExecutionFailed

    • ContinueAsNewWorkflowExecutionFailed

    • DecisionTaskTimedOut

    • FailWorkflowExecutionFailed

    • RecordMarkerFailed

    • RequestCancelActivityTaskFailed

    • RequestCancelExternalWorkflowExecutionFailed

    • ScheduleActivityTaskFailed

    • SignalExternalWorkflowExecutionFailed

    • StartActivityTaskFailed

    • StartChildWorkflowExecutionFailed

    • StartTimerFailed

    • TimerCanceled

    • LambdaFunctionFailed

    • LambdaFunctionTimedOut

    • StartLambdaFunctionFailed

    • ScheduleLambdaFunctionFailed

Amazon SWF 事件示例

以下是 Amazon SWF 向 EventBridge 发送事件的示例:

在每种情况下,事件数据中的 detail 部分都提供与 DescribeWorkflowExecution API 相同的信息。executionStatus 字段表示事件发送时的执行状态,即 OPENCLOSED

执行已启动

{ "version": "0", "id": "444444444444", "detail-type": "Simple Workflow Execution State Change", "source": "aws.swf", "account": "444444444444", "time": "2020-05-08T15:57:38Z", "region": "us-east-1", "resources": [ "arn:aws:swf:us-east-1:444444444444:/domain/SimpleWorkflowUserSimulator" ], "detail": { "eventId": 1, "eventType": "WorkflowExecutionStarted", "workflowExecutionDetail": { "executionInfo": { "execution": { "workflowId": "123456789012", "runId": "AKIAIOSFODNN7EXAMPLE" }, "workflowType": { "name": "SimpleWorkflowUserSimulator", "version": "myWorkflow" }, "startTimestamp": 1588953458484, "closeTimestamp": null, "executionStatus": "OPEN", "closeStatus": null, "parent": null, "parentExecutionArn": null, "tagList": null, "cancelRequested": false }, "executionConfiguration": { "taskStartToCloseTimeout": "60", "executionStartToCloseTimeout": "1000", "taskList": { "name": "444444444444" }, "taskPriority": null, "childPolicy": "ABANDON", "lambdaRole": "arn:aws:iam::444444444444:role/BasicSWFLambdaExecution" }, "openCounts": { "openActivityTasks": 0, "openDecisionTasks": 1, "openTimers": 0, "openChildWorkflowExecutions": 0, "openLambdaFunctions": 0 }, "latestActivityTaskTimestamp": null, } } }

执行已完成

{ "version": "0", "id": "1111-2222-3333", "detail-type": "Simple Workflow Execution State Change", "source": "aws.swf", "account": "444455556666", "time": "2020-05-08T15:57:39Z", "region": "us-east-1", "resources": [ "arn:aws:swf:us-east-1:444455556666:/domain/SimpleWorkflowUserSimulator" ], "detail": { "eventId": 35, "eventType": "WorkflowExecutionCompleted", "workflowExecutionDetail": { "executionInfo": { "execution": { "workflowId": "1234-5678-9012", "runId": "777788889999" }, "workflowType": { "name": "SimpleWorkflowUserSimulator", "version": "myWorkflow" }, "startTimestamp": 1588953458820, "closeTimestamp": 1588953459448, "executionStatus": "CLOSED", "closeStatus": "COMPLETED", "parent": null, "parentExecutionArn": null, "tagList": null, "cancelRequested": false }, "executionConfiguration": { "taskStartToCloseTimeout": "60", "executionStartToCloseTimeout": "1000", "taskList": { "name": "1111-1111-1111" }, "taskPriority": null, "childPolicy": "ABANDON", "lambdaRole": "arn:aws:iam::444455556666:role/BasicSWFLambdaExecution" }, "openCounts": { "openActivityTasks": 0, "openDecisionTasks": 0, "openTimers": 0, "openChildWorkflowExecutions": 0, "openLambdaFunctions": 0 }, "latestActivityTaskTimestamp": 1588953459402, } } }

执行已失败

{ "version": "0", "id": "1111-2222-3333", "detail-type": "Simple Workflow Execution State Change", "source": "aws.swf", "account": "444455556666", "time": "2020-05-08T15:57:38Z", "region": "us-east-1", "resources": [ "arn:aws:swf:us-east-1:444455556666:/domain/SimpleWorkflowUserSimulator" ], "detail": { "eventId": 11, "eventType": "WorkflowExecutionFailed", "workflowExecutionDetail": { "executionInfo": { "execution": { "workflowId": "1234-5678-9012", "runId": "777788889999" }, "workflowType": { "name": "SimpleWorkflowUserSimulator", "version": "myWorkflow" }, "startTimestamp": 1588953158481, "closeTimestamp": 1588953458560, "executionStatus": "CLOSED", "closeStatus": "FAILED", "parent": null, "parentExecutionArn": null, "tagList": null, "cancelRequested": false }, "executionConfiguration": { "taskStartToCloseTimeout": "60", "executionStartToCloseTimeout": "1000", "taskList": { "name": "1111-1111-1111" }, "taskPriority": null, "childPolicy": "ABANDON", "lambdaRole": "arn:aws:iam::444455556666:role/BasicSWFLambdaExecution" }, "openCounts": { "openActivityTasks": 0, "openDecisionTasks": 0, "openTimers": 0, "openChildWorkflowExecutions": 0, "openLambdaFunctions": 0 }, "latestActivityTaskTimestamp": null, } } }

执行超时

{ "version": "0", "id": "1111-2222-3333", "detail-type": "Simple Workflow Execution State Change", "source": "aws.swf", "account": "444455556666", "time": "2020-05-05T17:26:30Z", "region": "us-east-1", "resources": [ "arn:aws:swf:us-east-1:444455556666:/domain/SimpleWorkflowUserSimulator" ], "detail": { "eventId": 6, "eventType": "WorkflowExecutionTimedOut", "workflowExecutionDetail": { "executionInfo": { "execution": { "workflowId": "1234-5678-9012", "runId": "777788889999" }, "workflowType": { "name": "SimpleWorkflowUserSimulator", "version": "myWorkflow" }, "startTimestamp": 1588698073748, "closeTimestamp": 1588699590745, "executionStatus": "CLOSED", "closeStatus": "TIMED_OUT", "parent": null, "parentExecutionArn": null, "tagList": null, "cancelRequested": false }, "executionConfiguration": { "taskStartToCloseTimeout": "60", "executionStartToCloseTimeout": "1000", "taskList": { "name": "1111-1111-1111" }, "taskPriority": null, "childPolicy": "ABANDON", "lambdaRole": "arn:aws:iam::444455556666:role/BasicSWFLambdaExecution" }, "openCounts": { "openActivityTasks": 1, "openDecisionTasks": 0, "openTimers": 0, "openChildWorkflowExecutions": 0, "openLambdaFunctions": 0 }, "latestActivityTaskTimestamp": 1588699585802, } } }

执行已终止

{ "version": "0", "id": "1111-2222-3333", "detail-type": "Simple Workflow Execution State Change", "source": "aws.swf", "account": "444455556666", "time": "2020-05-08T22:37:26Z", "region": "us-east-1", "resources": [ "arn:aws:swf:us-east-1:444455556666:/domain/canary" ], "detail": { "eventId": 48, "eventType": "WorkflowExecutionTerminated", "workflowExecutionDetail": { "executionInfo": { "execution": { "workflowId": "1234-5678-9012", "runId": "777788889999" }, "workflowType": { "name": "1111-1111-1111", "version": "1.3" }, "startTimestamp": 1588977445279, "closeTimestamp": 1588977446062, "executionStatus": "CLOSED", "closeStatus": "TERMINATED", "parent": null, "parentExecutionArn": null, "tagList": null, "cancelRequested": false }, "executionConfiguration": { "taskStartToCloseTimeout": "60", "executionStartToCloseTimeout": "120", "taskList": { "name": "1111-1111-1111-2222-2222-2222" }, "taskPriority": null, "childPolicy": "TERMINATE", "lambdaRole": null }, "openCounts": { "openActivityTasks": 0, "openDecisionTasks": 1, "openTimers": 0, "openChildWorkflowExecutions": 0, "openLambdaFunctions": 0 }, "latestActivityTaskTimestamp": 1588977445882, } } }