重试并捕获 AWS Step Function 任务

xbe*_*eta 5 amazon-web-services aws-step-functions

对于 StepFunctions,我们是否可以两者兼而有之Retry,并Catch在穷尽的情况下共同努力?

这是我的用例

  1. 作业失败
  2. 重试
  3. 重试耗尽,转至 Catch
  4. 捕获所有错误,移至下一个作业,并更新数据库表以标记此作业失败(另一项任务)
  5. 或者在第一次运行或重试成功后,转移到下一个作业
    "ExecuteMyJob": {
            "Type": "Task",
            "Resource": "arn:aws:states:::glue:startJobRun.sync",
            "Parameters": {
                "JobName.$": "$.jobName",
                "Arguments.$": "$.jobArguments"
            },
            "Retry" : [{
                "ErrorEquals": [ "States.TaskFailed", "States.Runtime" ],
                "MaxAttempts": 3,
                "IntervalSeconds": 60,
                "BackoffRate": 2
            }],
            "Catch": [{
                "ErrorEquals": [ "States.ALL" ],
                "Next": "MarkJobFailOnDbTable"
            }],
            "Next": "NextJobOnPreviousSuccess"
        }
Run Code Online (Sandbox Code Playgroud)

Poo*_*del 5

Step Functions 可让您同时拥有RetryCatch

https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

该链接中的复杂重试方案示例与您的示例类似:

"X": {
   "Type": "Task",
   "Resource": "arn:aws:states:us-east-1:123456789012:task:X",
   "Next": "Y",
   "Retry": [ {
      "ErrorEquals": [ "ErrorA", "ErrorB" ],
      "IntervalSeconds": 1,
      "BackoffRate": 2.0,
      "MaxAttempts": 2
   }, {
      "ErrorEquals": [ "ErrorC" ],
      "IntervalSeconds": 5
   } ],
   "Catch": [ {
      "ErrorEquals": [ "States.ALL" ],
      "Next": "Z"
   } ]
}
Run Code Online (Sandbox Code Playgroud)