我正在使用 Cloud Workflow 按顺序运行多个 Cloud Run 作业。完成作业 #1 后,我想在转到作业 #2 之前检查是否成功完成。在测试中,我看到作业 #1 返回以下状态结果 JSON:
"status": {
"completionTime": "2024-11-08T17:09:23.947071Z",
"conditions": [
{
"lastTransitionTime": "2024-11-08T17:09:23.947071Z",
"status": "True",
"type": "Completed"
},
{
"lastTransitionTime": "2024-11-08T17:08:32.322671Z",
"status": "True",
"type": "ResourcesAvailable"
},
{
"lastTransitionTime": "2024-11-08T17:08:35.183828Z",
"status": "True",
"type": "Started"
},
{
"lastTransitionTime": "2024-11-08T17:08:32.219908Z",
"status": "True",
"type": "ContainerReady"
}
],
所以,为了测试是否成功,我想我想要类似的东西:
- check_step1:
switch:
- condition: ${step1_result.status.conditions.type == "Completed"}
next: step2
但是,这在工作流程中不起作用。那么,我该如何编写正确的测试条件呢?
不是工作流程用户,但你激起了我的好奇心;-)
main:
steps:
- step-global-assign:
assign:
# Replace with `ExecutionStatus`
- conditions: [
{"status":"True","type":"ResourcesAvailable"},
{"status":"True","type":"Started"},
{"status":"False","type":"Completed"},
{"status":"True","type":"ContainerReady"},
]
# Assume false
- result: false
- step-for-loop:
for:
value: condition
in: ${conditions}
steps:
- step-loop-assign:
assign:
# True if type=="Completed" and status=="True"
# Once any `result` is true, then `result` is always true
# Was unsure how to break from the loop once a result is true
- result: ${result or (condition["type"] == "Completed" and condition["status"] == "True")}
- done:
return: ${result}