超时设置和重试策略提供了对工作流执行和活动执行的特定步骤的精细控制。
Workflow Execution with a single Activity Execution: Timeout periods

工作流执行超时

工作流执行超时是工作流执行可以执行 (在 Open 状态) 的最长时间,包括重试和 Continue-as-new 的状态。
Workflow Execution Timeout period
默认值为 ∞ (无限)。如果达到此超时,则工作流执行将变为超时状态。此超时与
工作流运行超时不同。 此超时最常用于经过一定时间后停止执行 Temporal Cron Job
相关文档📚 How to set a Workflow Execution Timeout in Godeveloper guide

工作流运行超时

工作流运行超时是单个工作流运行限制的最长时间。

Workflow Run Timeout period
默认设置为 Workflow Execution Timeout 相同的值 . 他的超时最常用于限制单个 Temporal Cron Job Execution 的执行时间 .
如果达到工作流运行超时,临时服务器将自动终止工作流执行。
相关文档📚 How to set a Workflow Run Timeout in Godeveloper guide

工作流任务超时

工作流任务超时是指在 WorkerTask Queue 中取出 Workflow Task 后,允许 Worker 执行该任务的最长时间。
工作流任务超时:
超时和重试策略 - 图4
默认值为10秒。这个超时主要用于识别Worker是否已经下线,以便工作流执行可以在不同的Worker上恢复。增加默认值的主要原因是为了适应工作流执行,工作流执行历史记录非常长,可能需要超过10秒的时间来加载Worker。
相关文档 📚 How to set a Workflow Task Timeout in Godeveloper guide

Schedule-To-Start 超时

Schedule To Start 超时是指从调度 Activity Task(放置在任务队列中)到 Worker 开始执行该活动任务所允许的最长时间。
Schedule-To-Start 超时时期:
超时和重试策略 - 图5
附加到活动执行的 Retry Policy 将重试活动任务执行。因此,Schedule-To- Start 应用于活动执行中的每个活动任务执行。
Start-To-Close 带重试的超时时期:
超时和重试策略 - 图6
该超时的两个主要用途为:

  1. 检测单个 Worker 是否崩溃。
  2. 检测轮询任务队列的工作人员队伍是否跟不上活动任务的速率。

Schedule-To- Start 的默认超时时间是 ∞(无限的)。
如果使用此超时,我们建议将此超时设置为工作流执行在所有可能的工作人员停机的情况下愿意等待活动执行的最长时间,并制定具体计划,将活动任务重新路由到不同的任务队列。无论重试策略如何,此超时都不会触发任何重试,因为重试会将活动任务放回同一任务队列中。提醒一下,除非您知道自己在做什么,否则我们不建议您使用此超时。
在大多数情况下,我们建议监控 temporal_activity_schedule_to_start_latency 度量来知道工作人员何时不接收活动任务,而不是设置此超时。
相关文档 📚 How to set a Schedule-To-Start Timeout in Godeveloper guide

Start-To-Close 超时

Start-To- Close 超时是运行单个 Activity Task Execution 的最长时间。
Start-To-Close 的默认超时时间和 Schedule-To-Close 相同。
活动执行必须具有该超时 (Start-To-Close) 或 Schedule-To-Close 超时设置。我们建议始终设置该超时; 但是,请确保始终将其设置为比活动执行的最大可能时间长。对于长时间运行的活动执行,我们建议使用活动心跳心跳超时
Start-To-Close 超时的主要用于检测工作人员开始执行活动任务后何时崩溃。
超时和重试策略 - 图7
重试策略附加到活动执行会重试活动任务执行。因此,Start-T-Close 超时应用于活动执行中的每个活动任务执行。
如果第一个活动任务执行首次返回错误,则完整活动执行可能如下所示:
超时和重试策略 - 图8
如果到达超时时间,则会执行以下操作:

  • ActivityTaskTimedOut 事件被写入工作流执行的可变状态。
  • 如果重试策略要求重试,则 Temporal 集群会调度另一个活动任务。
    • 在工作流执行的可变状态下,尝试计数加1。
    • 重置 Start-To-Close 超时计时器。

如何实施

  • How to set a Start-To-Close Timeout in Go

    Schedule-To-Close 超时

    A Schedule-To-Close Timeout is the maximum amount of time allowed for the overall Activity Execution, from when the first Activity Task is scheduled to when the last Activity Task, in the chain of Activity Tasks that make up the Activity Execution, reaches a Closed status.Schedule-To-Close 超时是运行活动执行的最长时间,从首次活动任务计划到组成活动执行的活动任务链中的最后一个活动任务达到关闭状态。
    Schedule-To-Close 超时时期
    超时和重试策略 - 图9
    Example Schedule-To-Close Timeout period for an Activity Execution that has a chain Activity Task Executions:具有链活动任务执行的活动执行的计划关闭超时时间示例:
    Schedule-To-Close Timeout period with a retry通过重试计划关闭超时时间
    超时和重试策略 - 图10
    The default Schedule-To-Close Timeout is ∞ (infinity).默认的计划关闭超时为 ∞ (无穷大)。
    An Activity Execution must have either this timeout (Schedule-To-Close) or Start-To-Close set. By default an Activity Execution Retry Policy dictates that retries will occur for up to 10 years. This timeout can be used to reduce the overall time that has elapsed, without altering the default Retry Policy.活动执行必须具有此超时 (计划关闭) 或从开始到结束设置。默认情况下,活动执行重试策略指示重试将持续10年。此超时可用于减少已过去的总时间,而无需更改默认重试策略。
    相关文档 📚 How to set a Schedule-To-Close Timeout in Godeveloper guide

    Heartbeat 超时

    A Heartbeat Timeout is the maximum time between Activity Heartbeats.心跳超时是介于
    活动心跳。
    Heartbeat Timeout periods心跳超时时期
    超时和重试策略 - 图11
    If this timeout is reached, the Activity Execution changes to a Failed status, and will retry if a Retry Policy dictates it.如果达到此超时,则活动执行将更改为失败状态,如果重试策略指示,将重试。
    相关文档 📚 How to set a Heartbeat Timeout in Godeveloper guide

    重试策略

    A Retry Policy is collection of attributes that instructs the Temporal Server how to retry a failure of a Workflow Execution or an Activity Task Execution.重试政策收集属性指示时间服务器重试失败工作流执行或者活动任务执行。

  • If a custom Retry Policy is to be used, it must be provided as an options parameter when a Workflow Execution or an Activity Execution is invoked.如果要使用自定义重试策略,则当工作流执行或者活动执行被调用。

  • The wait time before a retry is the retry interval. A retry interval is the smaller of two values:重试之前的等待时间是重试间隔。重试间隔是两个值中较小的一个:
  • When a Workflow Execution is invoked it is not associated with a default Retry Policy and thus does not retry by default. The intention is that a Workflow Definition should be written to never fail due to intermittent issues; an Activity is designed to handle such issues.当一个工作流执行被调用它不与默认重试策略关联,因此默认情况下不重试。其目的是,应编写一个工作流定义,使其永远不会因间歇性问题而失败; 一项活动旨在处理此类问题。

    注意

    Retry Policies do not apply to Workflow Task Executions, which, by default, retry indefinitely.重试策略不适用于工作流任务执行,默认情况下,无限期重试。

  • A Retry Policy can be provided to a Workflow Execution when it is invoked, but only certain scenarios merit doing this, such as the following:重试政策可以提供工作流执行当调用它时,但只有某些场景值得这样做,例如:

    • A cron Workflow or some other stateless, always-running Workflow Execution that can benefit from retries.cron工作流或其他可从重试中受益的无状态、始终运行的工作流执行。
    • A file-processing or media-encoding Workflow Execution that downloads files to a host.将文件下载到主机的文件处理或媒体编码工作流执行。
  • When an Activity Execution is spawned, it is associated with a default Retry Policy, and thus Activity Task Executions are retried by default. When an Activity Task Execution is retried, the Server places a new Activity Task into its respective Activity Task Queue, which results in a new Activity Task Execution.当一个活动执行是生成的,它与默认重试策略相关联,因此活动任务执行默认情况下重试。当一个活动任务执行重试后,服务器会放置一个新的活动任务进入它各自的活动任务队列,这将导致新的活动任务执行。

Default values for Retry Policy重试策略的默认值
Initial Interval = 1 second
Backoff Coefficient = 2.0
Maximum Interval = 100 × Initial Interval
Maximum Attempts = ∞
Non-Retryable Errors = []

Copy

Initial Interval

  • Description: Amount of time that must elapse before the first retry occurs.描述: 第一次重试之前必须经过的时间量。
    • The default value is 1 second.默认值为1秒。
  • Use case: This is used as the base interval time for the Backoff Coefficient to multiply against.用例: 这是作为底座间隔时间退避系数乘以。

    Backoff Coefficient退避系数

  • Description: The value dictates how much the retry interval increases.描述: 该值决定了重试间隔增加。

    • The default value is 2.0.默认值为2.0。
    • A backoff coefficient of 1.0 means that the retry interval always equals the Initial Interval.回退系数为1.0意味着重试间隔始终等于初始间隔。
  • Use case: Use this attribute to increase the interval between retries. By having a backoff coefficient greater than 1.0, the first few retries happen relatively quickly to overcome intermittent failures, but subsequent retries happen farther and farther apart to account for longer outages. Use the Maximum Interval attribute to prevent the coefficient from increasing the retry interval too much.用例: 使用此属性可增加重试之间的间隔。通过使退避系数大于1.0,前几次重试发生得相对较快,以克服间歇性故障,但随后的重试发生得越来越远,以解释更长的中断。使用最大间隔属性可防止系数过多增加重试间隔。

    Maximum Interval最大间隔

  • Description: Specifies the maximum interval between retries.描述: 指定重试之间的最大间隔。

    • The default value is 100 times the Initial Interval.默认值是100倍初始间隔。
  • Use case: This attribute is useful for Backoff Coefficients that are greater than 1.0 because it prevents the retry interval from growing infinitely.用例: 此属性对退避系数大于1.0,因为它可以防止重试间隔无限增长。

    Maximum Attempts最大尝试次数

  • Description: Specifies the maximum number of execution attempts that can be made in the presence of failures.描述: 指定在存在失败的情况下可以进行的最大执行尝试次数。

    • The default is unlimited.默认值为unlimited。
    • If this limit is exceeded, the execution fails without retrying again. When this happens an error is returned.如果超过此限制,则执行将失败,而不会再次重试。发生这种情况时,将返回错误。
    • Setting the value to 0 also means unlimited.将该值设置为0也意味着无限制。
    • Setting the value to 1 means a single execution attempt and no retries.将值设置为1表示一次执行尝试,不重试。
    • Setting the value to a negative integer results in an error when the execution is invoked.将值设置为负整数会在调用执行时导致错误。
  • Use case: Use this attribute to ensure that retries do not continue indefinitely. However, in the majority of cases, we recommend relying on the Workflow Execution Timeout, in the case of Workflows, or Schedule-To-Close Timeout, in the case of Activities, to limit the total duration of retries instead of using this attribute.用例: 使用此属性确保重试不继续无限期。然而,在大多数情况下,我们建议依靠工作流执行超时,工作流,或计划关闭超时,活动,限制总时间重试而不是使用此属性。

    Non-Retryable Errors不可重试错误

  • Description: Specifies errors that shouldn’t be retried.描述: 指定不应重试的错误。

    • Default is none.默认值为none。
    • If one of those errors occurs, the Activity Task Execution or Workflow Execution is not retried.如果其中一个错误发生,活动任务执行或工作流执行不会重试。
  • Use case: There may be errors that you know of that should not trigger a retry. In this case you can specify them such that if they occur, the given execution will not be retried.用例: 您可能知道某些错误不应触发重试。在这种情况下,您可以指定它们,这样,如果它们发生,则不会重试给定的执行。

Related 📚