google-workflows

Using try and next in the same step in a GCP Workflow


What I have:

- wait:
    try:
        call: sys.sleep
        args:
            seconds: 5
        next: checkWorkflowInvocationStatus
    except:
        as: e
        <alert on an exception here>

The error I get:

parse error: in workflow 'main', step 'wait': unexpected entry 'next'

It works if I remove the try/except. Can next and try really not work together?


Solution

  • As per testing and replication, I've managed to fix it by aligning next: checkWorkflowInvocationStatus with try: instead of args:. My code looks like this:

    - wait:
        try:
            call: sys.sleep
            args:
                seconds: 5
        next: checkWorkflowInvocationStatus
        except:
            as: e
            <alert on an exception here>
    

    Or you may keep the same format and add a name for call: sys.sleep, e.g., sleepStep:. The code should look like this:

    - wait:
        try:
          steps:
          - sleepStep:
            call: sys.sleep
            args:
                seconds: 5
            next: checkWorkflowInvocationStatus
        except:
            as: e
            <alert on an exception here>