Skip to content

Instantly share code, notes, and snippets.

@shortjared
Created Jul 31, 2020
Embed
What would you like to do?
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