python - 门户中不存在 Azure 函数 timeTrigger

标签 python azure azure-functions

我有一个在 Linux 系统中运行的 azure 函数应用程序。在其中,我创建了两个函数,一个由 blob 触发器触发,另一个由 timetrigger 触发。
这两个功能都是通过azure DevOps部署的,但是当我进入门户时,时间触发功能不存在。
为了部署这些功能,我在 Git 存储库中拥有代码,并将其复制到 .zip 文件夹以构建工件。构建工件后,将使用 azure cli 将其部署到功能应用程序。

代码:

函数.json

{
    "schedule": "0 30 14 * * *",
    "name": "myTimer",
    "type": "timerTrigger",
    "direction": "in",
    "runOnStartup": false
}

主机.json

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true
      }
    }
  },
  "extensions": {
    "queues": {
      "maxPollingInterval": "00:00:02",
      "visibilityTimeout" : "00:00:30",
      "batchSize": 8,
      "maxDequeueCount": 5,
      "newBatchThreshold": 4,
      "messageEncoding": "base64"
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.3.0, 4.0.0)"
  },
  "functionTimeout": "-1",
  "retry": {
    "strategy": "fixedDelay",
    "maxRetryCount": 0,
    "delayInterval": "00:00:05"
  }
    
}

init.py

import datetime
import logging

import azure.functions as func


def main(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

解决方案
我配置了错误的 function.json 文件。正确的内容是:

{
  "bindings": [
    {
    "schedule": "0 30 14 * * *",
    "name": "myTimer",
    "type": "timerTrigger",
    "direction": "in",
    "runOnStartup": false
}
  ],
  "disabled": false,
  "scriptFile": "__init__.py"
}

最佳答案

感谢您确认@vll1990, 将解决方案作为答案发布,这对于解决类似问题的其他成员来说是有益的,以便他们能够找到并解决他们的问题。

我们尝试使用计时器触发器创建一个 python azure 函数,并发现我们需要以下格式的 function.json 文件。

您使用的function.json是:

{
    "schedule": "0 30 14 * * *",
    "name": "myTimer",
    "type": "timerTrigger",
    "direction": "in",
    "runOnStartup": false
}

相反,我们需要在 .json 文件中添加值之前指定绑定(bind)。 例如:-

{
  "bindings": [
    {
    "schedule": "0 30 14 * * *",
    "name": "myTimer",
    "type": "timerTrigger",
    "direction": "in",
    "runOnStartup": false //
}
  ],
  "disabled": false,
  "scriptFile": "__init__.py"
}

enter image description here

部署后,我们将能够在 Portal 本身的函数应用程序中看到计时器函数。

enter image description here

有关更多信息,请参阅此微软文档 | Timer trigger for Azure Functions .

关于python - 门户中不存在 Azure 函数 timeTrigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72698107/

相关文章:

Python文件读取

python - 使用迭代格式化二维列表 - 均匀间距问题

Azure 功能和 AD B2C 集成

python - 如何将输入变量从数据工厂传递到我的持久函数

azure - 是否可以在一个 Web 应用程序中拥有 2 个 ASP.NET Core 站点?

azure - 每次创建 CosmosDB 文档时运行 Azure 函数应用并更新第二个集合中的文档

unit-testing - Visual Studio 2017 : Azure functions unit test and local. settings.json 问题

python - 如何在 3D 绘图中缩放和设置 RGB 正交轴

javascript - highcharts:Y 轴为 1 或 0 的图表

amazon-web-services - 将日志从特定 Pod 发送到外部服务器