Skip to content

Instantly share code, notes, and snippets.

@shortjared
Created July 31, 2020 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shortjared/39a64b7fc6ca3d3aeb96ae9a3492aa87 to your computer and use it in GitHub Desktop.
Save shortjared/39a64b7fc6ca3d3aeb96ae9a3492aa87 to your computer and use it in GitHub Desktop.
CDK State Machine
const STATUS = "$.status"
const RETRY_SECONDS = "$.retrySeconds"
const PENDING = "pending"
const PROGRESS = "in-progress"
const FAILED = "failed"
const COMPLETE = "complete"
const setPending = stepFunction.setStatus(this, props.table, PENDING);
const setProgress = stepFunction.setStatus(this, props.table, PROGRESS);
const setSuccess = stepFunction.setStatus(this, props.table, COMPLETE);
const setFailed = stepFunction.setStatus(this, props.table, FAILED);
const waitForNSeconds = this.waitTask("retry seconds", RETRY_SECONDS);
const definition = this.mapperTask()
.next(setPending)
.next(waitForNSeconds)
.next(setProgress)
.next(this.deliverTransactionTask())
.next(
new sfn.Choice(this, "Delivery success?")
.when(sfn.Condition.stringEquals(STATUS, COMPLETE), setComplete)
.when(sfn.Condition.stringEquals(STATUS, FAILED), setFailed)
.otherwise(setPending)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment