我正在尝试学习 Google Workflow 重试机制。我的实际要求是请求一个http.get
并且会得到一个文本响应,我必须检查那个文本,如果它不满足我的条件,它应该在 10 秒后重试。
因此,为了尝试一下,我制作了下面的示例,并从文档中了解到,标准重试不符合我的要求,因为它基于 http 返回代码,因此,我选择了自定义谓词并定义了一个子工作流程。并了解到我不能将任何参数传递给这个子工作流程,并尝试raise
按照一个示例出错。但是,这不会在代码窗口中显示任何错误,但在运行时失败
main:
steps:
- first_step:
try:
steps:
- getCurrentDay:
call: http.get
args:
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
result: currentDateTime
- setFromCallResult:
assign:
- dayName: ${currentDateTime.body.dayOfTheWeek}
- whatIsToday:
call: sys.log
args:
data: ${dayName + " is actually a day"}
severity: "INFO" # Optional
- callRetry:
switch:
- condition: ${dayName == "Thursday"}
raise: ${dayName}
retry:
predicate: ${my_own_predicate}
max_retries: 5
backoff:
initial_delay: 2
max_delay: 60
multiplier: 1
- last_step:
return: "OK"
my_own_predicate:
params: [dayName]
steps:
- checkRetryCond:
switch:
- condition: ${dayName == "Thursday"}
return: False
- otherwise:
return: True
以下是错误:
RuntimeError: "Thursday"
in step "first_step", routine "main", line: 24
"Thursday"
第 24 行是
predicate: ${my_own_predicate}
在这一点上,我无法弄清楚问题是什么