Cadence:更改工作流 cron 计划的最佳实践是什么?

Cadence: What is the best practice to change the workflow cron schedule?

我们有一个使用基于 cron 的调度的工作流程。我们需要支持一个用例来更改 cron 表达式。

这样做的最佳做法是什么?

TL;DR

使用相同的 workflowID 再次启动相同的 cron 工作流,IDReusePolicy = TerminteIfRunning

例子

与文档中一样,只有在取消或终止时,CRON 才会停止。所以你也可以terminate/cancel,然后再开始一个新的。但是如果用两个请求自己做,就没有一致性保证了。

使用 IDReusePolicy = TerminteIfRunning 将确保终止+启动是 Cadence 中的原子操作。

下面是使用示例

1.Start 一个 helloworld 工人

./bin/helloworld -m worker &
[1] 24808
2021-03-22T20:08:09.404-0700    INFO    common/sample_helper.go:97  Logger created.
2021-03-22T20:08:09.405-0700    DEBUG   common/factory.go:131   Creating RPC dispatcher outbound    {"ServiceName": "cadence-frontend", "HostPort": "127.0.0.1:7933"}
...
...
  1. 启动 cron 工作流程
$./cadence  --do samples-domain wf start --tl helloWorldGroup -w "test-cron" --execution_timeout 10 --cron "* * * * *" --wt "main.helloWorldWorkflow" -i '"Hello"'
Started Workflow Id: test-cron, run Id: 2d9f06f9-7e79-4c9d-942a-e2c6a20c9f85
  1. 更新 cron 工作流程
$./cadence  --do samples-domain wf start --tl helloWorldGroup -w "test-cron" --execution_timeout 10 --cron "* * * * *" --wt "main.helloWorldWorkflow"  -i '"Cadence"'  --workflowidreusepolicy 3 
Started Workflow Id: test-cron, run Id: 4344448d-5a95-4a91-a56e-ebc0b93b4d29

请注意,在 CLI 中:--workflowidreusepolicy 3 将设置 IDReusePolicy = TerminteIfRunning

CLI 用法将在此 PR 之后更新。

  1. 然后您应该能够看到 helloworld 工作流打印新值:
21-03-22T20:24:00.307-0700   INFO    helloworld/helloworld_workflow.go:29    helloworld workflow started {"Domain": "samples-domain", "TaskList": "helloWorldGroup", "WorkerID": "24808@IT-USA-25920@helloWorldGroup", "WorkflowType": "main.helloWorldWorkflow", "WorkflowID": "test-cron", "RunID": "1e2e6d2f-dcc7-410f-8d06-81c94622bbb7"}
2021-03-22T20:24:00.307-0700    DEBUG   internal/internal_event_handlers.go:470 ExecuteActivity {"Domain": "samples-domain", "TaskList": "helloWorldGroup", "WorkerID": "24808@IT-USA-25920@helloWorldGroup", "WorkflowType": "main.helloWorldWorkflow", "WorkflowID": "test-cron", "RunID": "1e2e6d2f-dcc7-410f-8d06-81c94622bbb7", "ActivityID": "0", "ActivityType": "main.helloWorldActivity"}
...