英文:
Using try and next in the same step in a GCP Workflow
问题
错误信息:
> 解析错误:在工作流程 'main' 中,步骤 'wait' 中出现意外的条目 'next'
如果我删除 try
/except
,它就可以正常工作。next
和 try
真的不能一起使用吗?
英文:
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: checkWorkflowInvocationStatus
与try:
对齐,而不是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
<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>
Hope this helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论