timer trigger azure function python v2 model -部署到azure后,它说“no http trigger found”

hyrbngr7  于 2023-03-31  发布在  Python
关注(0)|答案(1)|浏览(157)

我正在尝试部署一个定时触发器(schedule)函数到azure函数使用python v2模型。函数在本地按预期工作。我正在使用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.
qncylg1j

qncylg1j1#

来自给定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 Timer Triggered Azure Function时,它给出了相同的结果,因为实际的本地函数项目不包含任何HTTP触发函数。

但我在Azure Function App Portal中获得了函数:

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

"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"

相关问题