Created
April 13, 2018 10:09
-
-
Save milancermak/722a937e9b7f866915b7d634fc611882 to your computer and use it in GitHub Desktop.
Gatekeeper loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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