我正在部署一个非常基本的 Azure Functions 应用程序来演示一些关键功能。
我有两个函数,一个演示 HTTP 触发器,另一个演示计时器触发器。两者都在本地实例上完美运行。
import azure.functions as func
import os
import datetime
import logging
app = func.FunctionApp()
@app.function_name(name="HttpTrigger1")
@app.route(route="keyvaulttest")
def test_function(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
test_phrase = os.getenv("TestEnvFromKeyVault")
logging.info(f'TestEnvFromKeyVault: {test_phrase}')
logging.info('Python HTTP trigger function ran at %s', utc_timestamp)
return func.HttpResponse(
test_phrase,
status_code=200
)
@app.function_name(name="TestTimer")
@app.schedule(schedule="0 */5 * * * *", arg_name="test_timer", use_monitor=False)
def test_function(test_timer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
test = os.getenv("TestEnvFromKeyVault")
if test_timer.past_due:
logging.info('The timer is past due!')
logging.info(f'TestEnvFromKeyVault: {test}')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
当我尝试使用 VSCode Azure Function 扩展命令“Azure Functions:部署到 FunctionApp”进行部署时,它表示已成功部署。我的 HTTP 触发器功能已部署并且可以工作,但我的计时器触发器功能未部署。
12:13:48 PM testapp: Deployment successful. deployer = ms-azuretools-vscode deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
最佳答案
我做了上述解决方案所做的事情(包括配置),但仍然发现自己遇到了OP描述的相同问题。在与 Microsoft 支持人员进行通话并进行所有操作后,最终删除了该行:
@app.function_name(name="HttpTrigger1")
...显然在 v2 中,函数名称是像任何其他函数一样从 def test_function
读取的,并且上面的行在上传时会导致读取函数的干扰。
关于python - Azure Functions Python V2 计时器触发器未部署,但在 VSCode 中状态成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75354503/