gpt4 book ai didi

python - 计时器触发 azure 函数 python v2 模型 - 部署到 azure 后,它显示 "no http trigger found "

转载 作者:行者123 更新时间:2023-12-03 06:21:10 25 4
gpt4 key购买 nike

我正在尝试使用 python v2 model 将时间触发(计划)函数部署到 azure 函数。该函数在本地按预期工作。我正在使用 VSCode 和 Azurite 扩展进行部署。部署似乎成功,但它说“未找到 HTTP 触发器”(这没有任何意义,因为它不是 HTTP triffered 函数),并且该函数实际上未部署到 Azure。这里可能出了什么问题?

function_app.py

import azure.functions as func

import datetime
import logging
import requests
import json
import sys
import os

CRON_SCHEDULE = "*/10 * * * * *"

app = func.FunctionApp()
@app.function_name(name="testSendReqToApiTimeTrigger")
@app.schedule(schedule=CRON_SCHEDULE, arg_name="mytimer", run_on_startup=False, use_monitor=True)
def makeApiCall(mytimer: func.TimerRequest, context: func.Context) -> None:

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

logging.info('.context_func_dir: ' + context.function_directory)

url = "http://worldtimeapi.org/api/timezone/Europe/Amsterdam"

try:
response = requests.get(url)
print(f"request completed with status code: {response.status_code}")

except:
logging.error("ERROR during sending request : ")
logging.error(str(sys.exc_info()))

部署过程输出的最后几行:

...
11:24:06 AM test-timer-function: Deployment successful. deployer = ms-azuretools-vscode deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
11:24:20 AM test-timer-function: Syncing triggers...
11:24:29 AM test-timer-function: Querying triggers...
11:24:34 AM test-timer-function: No HTTP triggers found.

最佳答案

来自给定MS Doc的源代码.

import  azure.functions  as  func
import logging
import datetime

app = func.FunctionApp()

@app.function_name(name="mytimer")
@app.schedule(schedule="0 */5 * * * *", arg_name="mytimer", run_on_startup=True,
use_monitor=False)
def test_function(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)

当我部署 Python v2 计时器触发的 Azure 函数时,它给出相同的结果,因为实际的本地函数项目不包含任何 HTTP 触发函数。

enter image description here

但是我在 Azure Function App Portal 中获取了这些函数:

enter image description here

因为在Python V2编程模型中,我们必须在Portal Function App Configuration中显式添加一个应用程序设置:

"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"

enter image description here

关于python - 计时器触发 azure 函数 python v2 模型 - 部署到 azure 后,它显示 "no http trigger found ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75875670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com