{
  "Comment": "Video ingestion workflow.",
  "StartAt": "StartWorkflow",
  "TimeoutSeconds": 172800,
  "States": {
    "StartWorkflow": {
      "Type": "Task",
      "Resource": "${daemon_video_start_workflow_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "ChooseTransferType"
    },
    "ChooseTransferType": {
      "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.workflow_job_type",
          "StringEquals": "workflow_ingest_from_s3",
          "Next": "TransferFromS3ToS3"
        },
        {
          "Variable": "$.workflow_job_type",
          "StringEquals": "workflow_ingest_from_browser",
          "Next": "TransferFromBrowserToS3"
        },
        {
          "Variable": "$.workflow_job_type",
          "StringEquals": "workflow_ingest_from_google_drive",
          "Next": "TransferFromGoogleDriveToS3"
        },
        {
          "Variable": "$.workflow_job_type",
          "StringEquals": "workflow_ingest_from_dropbox",
          "Next": "TransferFromDropboxToS3"
        }
      ]
    },
    "TransferFromS3ToS3": {
      "Type": "Task",
      "Resource": "${daemon_video_transfer_from_s3_to_s3_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 10800,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "MetadataExtraction"
    },
    "TransferFromBrowserToS3": {
      "Type": "Task",
      "Resource": "${daemon_video_transfer_from_browser_to_s3_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "CheckIfTransferFromBrowserToS3IsDoneAfterDelay"
    },
    "CheckIfTransferFromBrowserToS3IsDone": {
      "Type": "Task",
      "Resource": "${daemon_video_is_transfer_from_browser_to_s3_done_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "ContinueOnlyIfTransferFromBrowserToS3IsDone"
    },
    "LogTransferCompleted": {
      "Type": "Task",
      "Resource": "${daemon_video_log_transfer_completed_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "MetadataExtraction"
    },
    "LogTransferTimedOut": {
      "Type": "Task",
      "Resource": "${daemon_video_log_transfer_timed_out_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "End": true
    },
    "ContinueOnlyIfTransferFromBrowserToS3IsDone": {
      "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.is_transfer_from_browser_to_s3_done",
          "BooleanEquals": true,
          "Next": "LogTransferCompleted"
        },
        {
          "Variable": "$.has_transfer_from_browser_to_s3_timed_out",
          "BooleanEquals": true,
          "Next": "LogTransferTimedOut"
        },
        {
          "Variable": "$.is_transfer_from_browser_to_s3_done",
          "BooleanEquals": false,
          "Next": "CheckIfTransferFromBrowserToS3IsDoneAfterDelay"
        }
      ]
    },
    "CheckIfTransferFromBrowserToS3IsDoneAfterDelay": {
      "Type": "Wait",
      "Seconds": 10,
      "Next": "CheckIfTransferFromBrowserToS3IsDone"
    },
    "MetadataExtraction": {
      "Type": "Task",
      "Resource": "${daemon_video_extract_metadata_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "ValidateMetadata"
    },
    "TransferFromGoogleDriveToS3": {
      "Type": "Task",
      "Resource": "${daemon_video_transfer_from_google_drive_to_s3_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "MetadataExtraction"
    },
    "TransferFromDropboxToS3": {
      "Type": "Task",
      "Resource": "${daemon_video_transfer_from_dropbox_to_s3_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "MetadataExtraction"
    },
    "ValidateMetadata": {
      "Type": "Task",
      "Resource": "${daemon_video_validate_metadata_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "VideoAndAudioStreamAnalysis"
    },
    "VideoAndAudioStreamAnalysis": {
      "Type": "Parallel",
      "Next": "ValidateAnalysis",
      "Branches": [
        {
          "StartAt": "DetectBlackIntervalsAtBeginningAndEndOfVideo",
          "States": {
            "DetectBlackIntervalsAtBeginningAndEndOfVideo": {
              "Type": "Task",
              "Resource": "${daemon_video_detect_black_intervals_at_beginning_and_end_of_video_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 60,
                "MaxAttempts": 5,
                "BackoffRate": 2.0
              }],
              "End": true
            }
          }
        },
        {
          "StartAt": "DetectSilentIntervalsAtBeginningAndEndOfAudio",
          "States": {
            "DetectSilentIntervalsAtBeginningAndEndOfAudio": {
              "Type": "Task",
              "Resource": "${daemon_video_detect_silent_intervals_at_beginning_and_end_of_audio_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 1200,
              "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 60,
                "MaxAttempts": 5,
                "BackoffRate": 2.0
              }],
              "End": true
            }
          }
        },
        {
          "StartAt": "DetectVideoLocationAndDimensionsWithinBlackBorder",
          "States": {
            "DetectVideoLocationAndDimensionsWithinBlackBorder": {
              "Type": "Task",
              "Resource": "${daemon_video_detect_video_location_and_dimensions_within_black_border_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 10800,
              "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 60,
                "MaxAttempts": 5,
                "BackoffRate": 2.0
              }],
              "End": true
            }
          }
        },
        {
          "StartAt": "DetectMaxVolume",
          "States": {
            "DetectMaxVolume": {
              "Type": "Task",
              "Resource": "${daemon_video_detect_max_volume_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 1200,
              "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 60,
                "MaxAttempts": 5,
                "BackoffRate": 2.0
              }],
              "End": true
            }
          }
        },
        {
          "StartAt": "CalculateAudioStats",
          "States": {
            "CalculateAudioStats": {
              "Type": "Task",
              "Resource": "${daemon_video_calculate_audio_stats_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 1200,
              "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 60,
                "MaxAttempts": 5,
                "BackoffRate": 2.0
              }],
              "End": true
            }
          }
        }
      ]
    },
    "ValidateAnalysis": {
      "Type": "Task",
      "Resource": "${daemon_video_validate_analysis_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "CreateStreamablePreviewAndThumbnails"
    },
    "CreateStreamablePreviewAndThumbnails": {
      "Type": "Task",
      "Resource": "${daemon_video_create_streamable_preview_and_thumbnails_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 1800,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "CheckIfCreateStreamablePreviewAndThumbnailsIsDoneAfterDelay"
    },
    "CheckIfCreateStreamablePreviewAndThumbnailsIsDone": {
      "Type": "Task",
      "Resource": "${daemon_video_is_create_streamable_preview_and_thumbnails_done_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "Next": "ContinueOnlyIfCreateStreamablePreviewAndThumbnailsIsDone"
    },
    "ContinueOnlyIfCreateStreamablePreviewAndThumbnailsIsDone": {
      "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.is_create_streamable_preview_and_thumbnails_done",
          "BooleanEquals": true,
          "Next": "EndWorkflow"
        },
        {
          "Variable": "$.is_create_streamable_preview_and_thumbnails_done",
          "BooleanEquals": false,
          "Next": "CheckIfCreateStreamablePreviewAndThumbnailsIsDoneAfterDelay"
        }
      ]
    },
    "CheckIfCreateStreamablePreviewAndThumbnailsIsDoneAfterDelay": {
      "Type": "Wait",
      "Seconds": 10,
      "Next": "CheckIfCreateStreamablePreviewAndThumbnailsIsDone"
    },
    "EndWorkflow": {
      "Type": "Task",
      "Resource": "${daemon_video_end_workflow_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 86400,
      "Retry": [{
        "ErrorEquals": ["States.Timeout"],
        "IntervalSeconds": 60,
        "MaxAttempts": 5,
        "BackoffRate": 2.0
      }],
      "End": true
    }
  }
}
