jhuapl-boss / heaviside

Python library and DSL for working with AWS StepFunctions
Apache License 2.0
35 stars 10 forks source link

Goto support #11

Closed derek-pryor closed 5 years ago

derek-pryor commented 5 years ago

Adding support for a new Goto("state name") state that will allow jumping to any state within the branch of execution. Added a check to verify that the named state is valid.

Added for mainly for the use case of common error handling

Lambda("function1")
    catch []: '$.error'
        Goto("handler")

Lambda("function2")
    catch []: '$.error'
        Goto("handler")

Lambda("function3")
    catch []: '$.error'
        Goto("handler")

Success()

Lambda("handler")
    """handler
    common error handler function
    """

Fail('error', 'cause')

Edit: Changed the syntax from Goto('state name') to goto 'state name'

sandyhider commented 5 years ago

Is it going to workout Ok if the script does a goto into the middle of an ASTStateParallel state?

Ok I see that error_invalid_goto_target.sfn actually tests that it doesn't allow parallel state being used in a jump. Thats good.

derek-pryor commented 5 years ago

Is Goto A State or a Flow Control? ... It looks like it is clearly a state. Perhaps add something in the documentation to explain why this is a state and not a Flow Control?

Yea, I realized that after I implemented it. I was thinking about changing it to goto "state name" to be more like a flow control structure...

derek-pryor commented 5 years ago

Is it going to workout Ok if the script does a goto into the middle of an ASTStateParallel state?

You cannot do that, as a parallel branches states are self contained. You also cannot goto from a parallel branch to outside of the parallel statement or another branch of the parallel statement. The target verification check helps prevent this.