{
  "Comment": "Ingestion a missing ddex products using grps data",
  "StartAt": "GetGrpsData",
  "States": {
    "GetGrpsData": {
      "Type": "Task",
      "Resource": "${lambda_get_grps_data_arn}",
      "Parameters": {
        "upc.$": "$.detail.requestParameters.upc",
        "grps_ingestion_id.$": "$.detail.requestParameters.grps_ingestion_id",
        "prod_no.$": "$.detail.requestParameters.prod_no"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "RepOwnerDoNotIngestException"
          ],
          "Next": "SetIngestionStateSuccess",
          "ResultPath": "$.errors"
        },
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CreateIngestionLock"
    },
    "CreateIngestionLock": {
      "Type": "Task",
      "Resource": "${lambda_create_ingestion_lock_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "LockfileExistsException"
          ],
          "IntervalSeconds": 60,
          "MaxAttempts": 60,
          "BackoffRate": 2,
          "MaxDelaySeconds": 240
        },
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "FindOrCreateAccount"
    },
    "FindOrCreateAccount": {
      "Type": "Task",
      "Resource": "${lambda_find_or_create_account_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        },
        {
          "ErrorEquals": [
            "GraphQLError"
          ],
          "IntervalSeconds": 20,
          "MaxAttempts": 2,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ProcesParticipants"
    },
    "ProcesParticipants": {
      "Type": "Task",
      "Resource": "${lambda_proces_participants_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        },
        {
          "ErrorEquals": [
            "GraphQLError"
          ],
          "IntervalSeconds": 20,
          "MaxAttempts": 2,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ReplaceWithPlaceholderUpc"
    },
    "ReplaceWithPlaceholderUpc": {
      "Type": "Task",
      "Resource": "${lambda_replace_with_placeholder_upc_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CreateProject"
    },
    "CreateProject": {
      "Type": "Task",
      "Resource": "${lambda_create_project_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "CreateProjectException",
            "DuplicateProjectCodeException",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        },
        {
          "ErrorEquals": [
            "GraphQLError"
          ],
          "IntervalSeconds": 20,
          "MaxAttempts": 2,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CreateProduct"
    },
    "CreateProduct": {
      "Type": "Task",
      "Resource": "${lambda_create_product_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "CreateProductException",
            "GraphQLError",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "ProductAlreadyExistsException"
          ],
          "Next": "SetIngestionStateSuccess",
          "ResultPath": "$.errors"
        },
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CreateTracks"
    },
    "CreateTracks": {
      "Type": "Task",
      "Resource": "${lambda_create_tracks_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "CreateTracksException",
            "GraphQLError",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "SetTrackMetadata"
    },
    "SetTrackMetadata": {
      "Type": "Map",
      "MaxConcurrency": 1,
      "ItemsPath": "$.tracks",
      "Parameters": {
        "track.$": "$$.Map.Item.Value",
        "context": {
          "correlation_id.$": "$.correlation_id",
          "project.$": "$.project",
          "product.$": "$.product",
          "label_participants.$": "$.label_participants",
          "product_type.$": "$.product_type"
        }
      },
      "Iterator": {
        "StartAt": "SetTrackMetadataTask",
        "States": {
          "SetTrackMetadataTask": {
            "Type": "Task",
            "Resource": "${lambda_set_track_metadata_arn}",
            "Retry": [
              {
                "ErrorEquals": [
                  "States.Timeout",
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException",
                  "Lambda.TooManyRequestsException"
                ],
                "IntervalSeconds": 5,
                "MaxAttempts": 5,
                "BackoffRate": 3
              }
            ],
            "Catch": [
              {
                "ErrorEquals": [
                  "States.ALL"
                ],
                "Next": "CatchSetTrackMetadataError"
              }
            ],
            "ResultPath": null,
            "Next": "TrackMetadataSuccess"
          },
          "TrackMetadataSuccess": {
            "Type": "Pass",
            "InputPath": null,
            "Result": null,
            "End": true
          },
          "CatchSetTrackMetadataError": {
            "Type": "Pass",
            "End": true
          }
        }
      },
      "ResultPath": "$.track_errors",
      "Next": "DetectErrors"
    },
    "DetectErrors": {
      "Type": "Task",
      "Resource": "${lambda_detect_errors_arn}",
      "Parameters": {
        "correlation_id.$": "$.correlation_id",
        "grps_ingestion_id.$": "$.grps_ingestion_id",
        "project.$": "$.project",
        "product.$": "$.product",
        "tracks.$": "$.tracks",
        "deleted_tracks.$": "$.deleted_tracks",
        "label_participants.$": "$.label_participants",
        "track_errors.$": "$.track_errors",
        "product_type.$": "$.product_type"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "SetProductToComplete"
    },
    "SetProductToComplete": {
      "Type": "Task",
      "Resource": "${lambda_set_product_to_complete_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "SetProductToCompleteException",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "SetIngestionStateSuccess"
    },
    "SetIngestionStateSuccess": {
      "Type": "Task",
      "Resource": "${lambda_set_ingestion_state_arn}",
      "Parameters": {
        "context.$": "$",
        "status": "Success"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "SetIngestionStateFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "RemoveIngestionLockFileSuccess"
    },
    "SetIngestionStateFailure": {
      "Type": "Task",
      "Resource": "${lambda_set_ingestion_state_arn}",
      "Parameters": {
        "context.$": "$",
        "status": "Failure"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 2
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "RemoveIngestionLockFileFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "RemoveIngestionLockFileFailure"
    },
    "RemoveIngestionLockFileSuccess": {
      "Type": "Task",
      "Resource": "${lambda_remove_ingestion_lock_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "FailState",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "SuccessState"
    },
    "RemoveIngestionLockFileFailure": {
      "Type": "Task",
      "Resource": "${lambda_remove_ingestion_lock_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "FailState",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "FailState"
    },
    "SuccessState": {
      "Type": "Succeed"
    },
    "FailState": {
      "Type": "Fail"
    }
  }
}
