Skip to content

Instantly share code, notes, and snippets.

@milancermak
Created April 13, 2018 10:09
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 milancermak/722a937e9b7f866915b7d634fc611882 to your computer and use it in GitHub Desktop.
Save milancermak/722a937e9b7f866915b7d634fc611882 to your computer and use it in GitHub Desktop.
Gatekeeper loop
class NotReadyError(Exception):
"""
Custom exception signaling to the Step Function
that it cannot move to the next state. Instead,
the Retry block is triggered, pausing the process.
You can pass details about the progress as a
string when initializing it. It will be shown
in the SF console.
"""
pass
def is_processing_done():
"""
Function checking if whatever external work the
pipeline is waiting on has finished already.
"""
return False
def main(event, context):
if event.get('force'):
return
if not is_processing_done():
raise NotReadyError()
{
"Comment": "Step Function demonstrating the gatekeeper loop",
"StartAt": "GatekeeperState",
"States": {
"GatekeeperState": {
"Type": "Task",
"Resource": "",
"Next": "DoneState",
"ResultPath": null,
"Retry": [{
"ErrorEquals": ["NotReadyError"],
"IntervalSeconds": 30,
"BackoffRate": 1.0,
"MaxAttempts": 50
}],
"Catch": [{
"ErrorEquals": ["NotReadyError"],
"ResultPath": "$.exception",
"Next": "ForceGatekeeperState"
}]
},
"ForceGatekeeperState": {
"Type": "Pass",
"Result": true,
"ResultPath": "$.force",
"Next": "GatekeeperState"
},
"DoneState": {
"Type": "Task",
"Resource": "",
"End": true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment