如果 Argo Workflow 已经在运行,如何防止它被重新提交?

问题描述

用例是我们考虑通过 Argo Events with PubSub 触发 Argo 工作流。 PubSub 不保证消息只传递一次。是否有一种简单的方法可以防止工作流在运行时再次被触发?

类似于 CronWorkflows 的 concurrencyPolicy 设置。

有一些东西要看 - 让我们假设 whalesay 工作流程:

apiVersion: argoproj.io/v1alpha1
kind: Workflow                  # new type of k8s spec
metadata:
  name: hello-world    # name of the workflow spec
  namespace: argo
spec:
  entrypoint: whalesay          # invoke the whalesay template
  templates:
  - name: whalesay              # name of the template
    container:
      image: docker/whalesay
      command: [cowsay]
      args: ["hello world"]
      resources:                # limit the resources
        limits:
          memory: 32Mi
          cpu: 100m

我发现了以下两个有希望的问题 - 但我未能提取此问题的解决方案。

解决方法

如果您只需要确保工作流不会同时运行多个实例,请使用 Argo 的内置 synchronization 功能。

apiVersion: v1
kind: ConfigMap
metadata:
 name: my-config
data:
  workflow: "1"  # Only one workflow can run at given time in particular namespace

---

apiVersion: argoproj.io/v1alpha1
kind: Workflow 
metadata:
  name: hello-world
spec:
  entrypoint: whalesay
  synchronization:
    semaphore:
      configMapKeyRef:
        name: my-config
        key: workflow
  templates:
  - name: whalesay
    container:
      image: docker/whalesay
# ...

如果您想避免处理同一条消息两次,您可以在工作流中添加一个步骤,以便在消息 ID 位于数据库(或类似内容)中时提前退出。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...