Azure函数Timetrigger在门户中不存在

发布于 2025-02-09 02:04:16 字数 1769 浏览 2 评论 0 原文

我有一个在Linux系统中运行的Azure函数应用程序。在其中,我创建了两个函数,一个功能是由斑点触发器触发的,另一个由Timetrigger触发。
两个功能都使用Azure DevOps部署,但是当我进入Portal时,Timetrigger函数不存在。
要部署函数,我将代码在git存储库中,并将其复制到.zip文件夹以构建工件。一旦构建了工件,就可以将其部署到使用Azure CLI功能应用程序。

函数

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

{
  "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"
  }
    
}

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)

代码 我配置了错误的函数。正确的内容是:

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

I have an azure function app running in Linux system. In it, I have create two functions, one is triggered by a blob trigger and the other with timetrigger.
Both functions are deployed with azure DevOps but when I go to portal, timetrigger function is not present.
To deploy the functions, I have the code in Git repository and it is copied to a .zip folder to build the artifact. Once artifact is built, it is deployed to function app with azure cli.

Code:

function.json

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

host.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)

SOLUTION
I had wrong configured function.json file. Correct content is:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杯别 2025-02-16 02:04:16

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

我们尝试使用计时器触发器创建Python Azure函数,并将其弄清楚为您需要以下面的格式使用 function.json 文件。

您正在使用的 function.json 是:

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

我们需要在我们的 .json 文件中添加值之前,需要指定 bindings
例如: -

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

“在此处输入图像描述”

,然后在部署后,我们将能够在门户网站本身的函数应用中查看计时器函数。

有关更多信息,请参阅此 Microsoft文档 | azure函数的计时器触发

Thanks for confirming @vll1990,
Posting the solution as an answer This will be beneficial for other members for the similar issue so that they can find and fix their issue.

We have tried to create a python azure function using timer trigger and figured out as you that we need to have our function.json file in below format.

The function.json that you are using is:

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

Instead of that We need to specify the bindings before adding the value in our .json file .
For example:-

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

enter image description here

And then after deploy we will be able to see the timer function in our function app on Portal itself.

enter image description here

For more information please refer this MICROSOFT DOCUMENT| Timer trigger for Azure Functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文