在 Argo Workflow 中,可以使用 RetryStrategy
对象设置任务重试的行为。其中,可以指定 backoffDuration
属性定义在重试时等待的时间。例如,以下代码展示如何设置等待时间为 3 秒钟,并分别尝试两次任务的步骤:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: retry-example
spec:
entrypoint: retry-step
templates:
- name: retry-step
retryStrategy:
limit: 2
backoff:
duration: "3s"
steps:
- - name: step-1
template: step-1
- - name: step-2
template: step-2
- name: step-1
script:
image: alpine:latest
command: [sh, -c]
source: |
echo "This is step 1."
exit 1
- name: step-2
script:
image: alpine:latest
command: [sh, -c]
source: |
echo "This is step 2."
在上面的示例中,由于第 1 步骤将退出代码设置为 1,因此将重试步骤两次。在每次重试之间等待 3 秒钟。
更多关于 RetryStrategy
对象的信息,请参阅 官方文档。