在GCP工作流中,在同一步骤中同时使用try和next。

huangapple go评论38阅读模式
英文:

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

问题

错误信息:

> 解析错误:在工作流程 'main' 中,步骤 'wait' 中出现意外的条目 'next'

如果我删除 try/except,它就可以正常工作。nexttry 真的不能一起使用吗?

英文:

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?

答案1

得分: 1

根据测试和复制,我已经成功修复了它,通过将next: checkWorkflowInvocationStatustry:对齐,而不是args:。我的代码看起来像这样:

- wait:
    try:
        call: sys.sleep
        args:
            seconds: 5
    next: checkWorkflowInvocationStatus
    except:
        as: e
        <在此处处理异常>

或者您可以保留相同的格式并为call: sys.sleep添加一个名称,例如sleepStep:。代码应该如下所示:

- wait:
    try:
      steps:
      - sleepStep:
        call: sys.sleep
        args:
            seconds: 5
        next: checkWorkflowInvocationStatus
    except:
        as: e
        <在此处处理异常>

希望这有所帮助。

英文:

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
        &lt;alert on an exception here&gt;

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
        &lt;alert on an exception here&gt;

Hope this helps.

huangapple
  • 本文由 发表于 2023年7月27日 18:59:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779073.html
  • google-workflows
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定