我有一个在 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"
}
部署后,我们将能够在 Portal 本身的函数应用程序中看到计时器函数。
有关更多信息,请参阅此微软文档 | Timer trigger for Azure Functions .
关于python - 门户中不存在 Azure 函数 timeTrigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72698107/