简体   繁体   English

节奏/时间工作流中的迭代活动

[英]Iterative activity in Cadence / Temporal workflow

This can be considered a follow-up question to Invoking the same activity inside a loop in cadence workflow : How does the workflow recover in case of activity iteration?这可以被认为是Invoking the same activity inside a loop in cadence workflow的后续问题:在活动迭代的情况下工作流如何恢复? Will is continue invoking the i-th activity (skipping the ones that were already invoked) or start again from 0?将继续调用第 i 个活动(跳过已调用的活动)还是从 0 重新开始? If so, how can the workflow be written so that activities that were invoked (0-'k') are skipped?如果是这样,如何编写工作流以便跳过调用的活动(0-'k')?

Each activity invocation has its own retry policy, so if activity i fails, only activity i will be retried.每个活动调用都有自己的重试策略,因此如果活动 i 失败,则只有活动 i 会被重试。

My understanding is those iterations are replayed when the history is retrieved in the rescuing worker.我的理解是,当在救援人员中检索历史时,这些迭代会被重播。

So iteration 1 had result 'x', iteration 2 had 'y' until it reaches the last activity that it hadn't recorded a result for, and then starts actually invoking the activities.所以迭代 1 的结果为“x”,迭代 2 的结果为“y”,直到它到达最后一个没有记录结果的活动,然后开始实际调用活动。

In this way, you can be sure the state of the workflow, and its potential variables, is exactly how it was when it terminated.通过这种方式,您可以确定工作流的 state 及其潜在变量与终止时的状态完全相同。

So they aren't exactly 'skipped' but they also don't re-execute.所以它们并没有完全“跳过”,但它们也不会重新执行。

If you don't want to replay hundreds of no-op iterations after a failure, you could consider using "continueAsNew" instead of a loop.如果您不想在失败后重播数百次无操作迭代,您可以考虑使用“continueAsNew”而不是循环。 This ensures the new workflow doesn't accrue the history of the other failed iterations.这可确保新工作流不会累积其他失败迭代的历史记录。

First of all, it's important to understand the difference between workflow worker vs activity worker.首先,了解工作流工作者与活动工作者之间的区别很重要。

  • Workflow worker only processes your workflow code (not inside the activities) and stops at Cadence API calls to schedule an activity, to start a timer etc. Workflow workers receive "decision tasks" where they execute the workflow code from last point it paused till the next API call.工作流工作者仅处理您的工作流代码(不在活动内部)并在 Cadence API 调用以安排活动、启动计时器等时停止。工作流工作者接收“决策任务”,他们在其中执行工作流代码,从最后一点暂停到下一个 API 调用。 When sticky workers are used, there will be a thread waiting on the last API call maintaining the local variables.当使用粘性工作器时,将有一个线程等待最后一次 API 调用维护局部变量。 If the worker didn't already have such thread, it will replay the workflow using the history first to understand where the workflow was supposed to be waiting.如果工作人员还没有这样的线程,它将首先使用历史记录重播工作流,以了解工作流应该在哪里等待。
  • Activity worker only executes "inside the activities" given activity parameters.活动工作者仅在给定活动参数的“活动内部”执行。 Think of like a cloud function.想像云function。 Activity workers will receive activity tasks containing activity parameters, they will execute the activity and return its result.活动工作者将接收包含活动参数的活动任务,他们将执行活动并返回其结果。 That's it.而已。

Coming back to your question: When your "workflow" worker crashes, restarts, lost or somehow a worker received a decision task that it doesn't know about its workflow;回到您的问题:当您的“工作流程”工作人员崩溃、重新启动、丢失或以某种方式接收到不了解其工作流程的决策任务时; it will then request the history of that workflow from Cadence servers.然后它将从 Cadence 服务器请求该工作流的历史记录。 It will replay the workflow until is consumes the whole history it receives then will schedule the next activity based on current local variables.它将重放工作流,直到消耗它收到的整个历史记录,然后将根据当前的局部变量安排下一个活动。

So it will continue from the same loop iteration with the same local variables and parameters to the activity.因此,它将使用相同的局部变量和参数从同一个循环迭代继续到活动。

Hope this answers your question希望这能回答你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM