{
  "Comment": "Create a job and Claim a list of contributions for a CMO.",
  "StartAt": "CreateJobs",
  "States": {
    "CreateJobs": {
      "Type": "Task",
      "Resource": "${create_jobs_lambda_arn}",
      "ResultPath": "$.jobs",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 3,
          "Comment": "Retry on timeout"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "JobCombiner",
          "Comment": "Error after retry"
        }
      ],
      "Next": "ProcessEachJob"
    },
    "ProcessEachJob": {
      "Type": "Map",
      "MaxConcurrency": 5,
      "Next": "JobCombiner",
      "ItemsPath": "$.jobs",
      "Iterator": {
        "StartAt": "Claimorizer",
        "States": {
          "Claimorizer": {
            "Type": "Task",
            "Resource": "arn:aws:states:::ecs:runTask.sync",
            "Parameters": {
              "LaunchType": "FARGATE",
              "Cluster": "${fargate_arn}",
              "TaskDefinition": "${fargate_task_arn}",
              "NetworkConfiguration": {
                "AwsvpcConfiguration": {
                  "Subnets": [
                    "subnet-b649dfef"
                  ],
                  "AssignPublicIp": "DISABLED"
                }
              },
              "Overrides": {
                "ContainerOverrides": [
                  {
                    "Name": "nr-sfn-fargate-poc",
                    "Environment": [
                      {
                        "Name": "TASK_TOKEN",
                        "Value.$": "$$.Task.Token"
                      },
                      {
                        "Name": "jobFile",
                        "Value.$": "$.jobFile"
                      }
                    ]
                  }
                ]
              }
            },
            "Retry": [
              {
                "ErrorEquals": [
                  "States.Timeout",
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException",
                  "Lambda.TooManyRequestsException"
                ],
                "BackoffRate": 2,
                "IntervalSeconds": 60,
                "MaxAttempts": 3,
                "Comment": "retry on timeout"
              }
            ],
            "Next": "GetObject",
            "ResultPath": null
          },
          "GetObject": {
            "Type": "Task",
            "Next": "MetadataGenerator",
            "Parameters": {
              "Bucket": "test-orcd-bucket",
              "Key.$": "$.jobFile"
            },
            "Resource": "arn:aws:states:::aws-sdk:s3:getObject",
            "ResultSelector": {
              "Body.$": "States.StringToJson($.Body)"
            },
            "OutputPath": "$.Body"
          },
          "MetadataGenerator": {
            "Type": "Task",
            "Resource": "${metadata_lambda_arn}",
            "ResultPath": "$.metadataResult",
            "End": true,
            "Retry": [
              {
                "ErrorEquals": [
                  "States.Timeout",
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException",
                  "Lambda.TooManyRequestsException"
                ],
                "BackoffRate": 2,
                "IntervalSeconds": 60,
                "MaxAttempts": 3,
                "Comment": "retry on timeout"
              }
            ]
          }
        },
        "ProcessorConfig": {
          "Mode": "DISTRIBUTED",
          "ExecutionType": "STANDARD"
        }
      },
      "ResultPath": "$.jobs",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "JobCombiner",
          "ResultPath": "$.jobErrors",
          "Comment": "For all job errors"
        }
      ],
      "Label": "ProcessEachJob"
    },
    "JobCombiner": {
      "Type": "Task",
      "Resource": "${combiner_lambda_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 3,
          "Comment": "retry on timeout"
        }
      ],
      "End": true
    }
  }
}
