带有参数的 Azure 函数上的两个计时器触发器

Two Timer Triggers on Azure Function With Params

我们有两个计时器触发器一个 Azure 函数 - 触发器 A 和触发器 B。如果触发器 A 被定义为“首先”,它会运行而触发器 B 不会。同样,如果首先定义触发器 B,它会运行而触发器 A 不会。

这引出了两个问题:

  1. 一个 Azure 函数可以有两个计时器触发器吗?我在文档中找不到任何内容。我发现最接近的是一个 SO 答案,暗示这是不可能的。
  2. 根据 official docs 的逗号分隔 NCRONTAB 表达式由于参数不同而无法在此处剪切,因此有什么好的解决方案?

我们很想将计时器触发器更改为 API 触发器,并在计时器上使用冗余功能应用程序调用具有不同参数的端点。

更新:

正如 Peter Bons 提到的,'call a shared method'。

原答案:

Can an Azure function have two timer triggers? I can't find anything in the documentation. Closest thing I found is a SO answer implying that this is impossible.

如果你说的是 azure function app,那是可以的。

但是如果你谈论的是单个 azure 函数,那么你不能将两个触发器放在一个函数中。

例如,下面的效果很好:

What is a good solution to this problem given that comma-delimited NCRONTAB expression as per the official docs does not cut it here due to the different params?

CRON表达式不能代表所有的用例,所以有时候需要在一个函数应用中把代码分成两个函数

如果你想要一个 'dynamic' CRON,你可以像下面那样做并改变相关值:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "%test%"
    }
  ]
}

以上是在portal上改的值,也可以设置环境变量。该值来自 env var.