跳转至

Function effects(函数效果(Function effects))

:::callout{theme="neutral" title="Beta"} Function effects are in the beta phase of development and may not be available on your enrollment. Functionality may change during active development. :::

Function effects allow you to automatically run functions when an automation triggers or recovers. Functions enable custom compute logic that can analyze data, transform inputs, and return computed results. Note that functions with ontology edit return types cannot apply these edits as part of a function effect; to apply the edit, you will need to use a function-backed action.

Configuration

To set up a function effect, open the automation configuration wizard. On the Effects page, add a Function effect; this will take you to the function effect configuration page. One function will already be added by default and will be displayed as Unconfigured.

Starting with this unconfigured function, search and select the function you want to execute. Then, specify the function version. For stable versions (versions 1.0.0 and greater), you can toggle on Auto upgrade to compatible versions which will automatically upgrade non-prerelease versions up to the next major version. This allows the automation to use newer compatible function versions as they become available.

After selecting the function, the interface will display the required and optional parameters for the selected function.

To add more functions, select Add Function. This will add another tab allowing you to configure a new action.

Asynchronous execution

Function effects execute asynchronously. When asynchronous execution is supported, the automation submits the function for execution and then polls for the result, rather than waiting synchronously for the function to complete. This can be used for long-running functions that may take significant time to compute. Functions can run up to 4 hours.

Note that function types that do not support asynchronous execution will execute synchronously.

Error handling

You can configure multiple ways to handle a failed function, including a retry strategy. Available retry strategies include:

  • Constant backoff: Automatically retry with a fixed wait time between attempts.
  • Exponential backoff: Wait time increases exponentially between retries.

You can also configure the amount of jitter, which is a variation in delay time between retries to prevent simultaneous retries. Jitter can be specified as:

  • A factor by which retry delays should be randomly varied. For each retry delay, a randomly selected fraction of the delay is multiplied by the factor and added or subtracted to the delay. For example, given a delay of 100 ms and a factor of 0.25, the retry delay would be between 75 ms and 125 ms.
  • A duration by which retry delays should be randomly varied. For each retry delay, a randomly selected fraction of the duration is added or subtracted to the delay. For example, given a delay of 100 ms with duration 20 ms, the retry delay would be between 80 ms and 120 ms.

For information about Function effect execution guarantees and how to handle potential duplicate executions, review the execution guarantees section in the execution settings documentation.

Permissions

Functions are associated with the owner of an automation. This means that the function will be run on behalf of the owner of the automation. The owner configuring a function must have the necessary permissions to execute that function.

:::callout{theme="warning"} Since functions run on behalf of a specific user (the owner of an automation), a function will no longer run if the associated user account is disabled or deleted. :::


中文翻译

函数效果(Function effects)

:::callout{theme="neutral" title="Beta"} 函数效果(Function effects)目前处于beta开发阶段,可能尚未在您的环境中启用。在活跃开发期间,功能可能会发生变化。 :::

函数效果允许您在自动化触发或恢复时自动运行函数。函数能够实现自定义计算逻辑,用于分析数据、转换输入并返回计算结果。请注意,具有本体编辑返回类型的函数无法将这些编辑作为函数效果的一部分应用;要应用编辑,您需要使用函数支持的操作(function-backed action)。

配置(Configuration)

要设置函数效果,请打开自动化配置向导。在效果(Effects)页面上,添加一个函数(Function)效果;这将带您进入函数效果配置页面。默认情况下已添加一个函数,并显示为未配置(Unconfigured)

从该未配置的函数开始,搜索并选择您要执行的函数。然后,指定函数版本。对于稳定版本(1.0.0及以上版本),您可以开启自动升级到兼容版本(Auto upgrade to compatible versions),该功能将自动将非预发布版本升级到下一个主要版本。这使得自动化能够在新的兼容函数版本可用时使用它们。

选择函数后,界面将显示所选函数的必需参数和可选参数。

要添加更多函数,请选择添加函数(Add Function)。这将添加另一个选项卡,允许您配置新的操作。

异步执行(Asynchronous execution)

函数效果异步执行。当支持异步执行时,自动化会提交函数执行,然后轮询结果,而不是同步等待函数完成。这适用于可能需要较长时间计算的长时间运行函数。函数最长可运行4小时。

请注意,不支持异步执行的函数类型将同步执行。

错误处理(Error handling)

您可以配置多种方式来处理失败的函数,包括重试策略。可用的重试策略包括:

  • 恒定退避(Constant backoff): 自动重试,每次尝试之间等待固定时间。
  • 指数退避(Exponential backoff): 重试之间的等待时间呈指数级增加。

您还可以配置抖动(jitter)量,即重试之间延迟时间的变化,以防止同时重试。抖动可以指定为:

  • 一个因子,重试延迟应据此随机变化。对于每次重试延迟,随机选择延迟的一部分乘以该因子,然后加到延迟上或从延迟中减去。例如,给定延迟100 ms和因子0.25,重试延迟将在75 ms125 ms之间。
  • 一个持续时间,重试延迟应据此随机变化。对于每次重试延迟,随机选择持续时间的一部分加到延迟上或从延迟中减去。例如,给定延迟100 ms和持续时间20 ms,重试延迟将在80 ms120 ms之间。

有关函数效果执行保证以及如何处理潜在重复执行的信息,请查阅执行设置文档中的执行保证部分。

权限(Permissions)

函数与自动化的所有者相关联。这意味着函数将以自动化所有者的身份运行。配置函数的所有者必须拥有执行该函数所需的权限。

:::callout{theme="warning"} 由于函数以特定用户(自动化的所有者)的身份运行,如果关联的用户账户被禁用或删除,函数将不再运行。 :::