python - Azure Functions Python V2 计时器触发器未部署,但在 VSCode 中状态成功

标签 python visual-studio-code azure-functions timer-trigger

我正在部署一个非常基本的 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.

enter image description here

最佳答案

我做了上述解决方案所做的事情(包括配置),但仍然发现自己遇到了OP描述的相同问题。在与 Microsoft 支持人员进行通话并进行所有操作后,最终删除了该行:

@app.function_name(name="HttpTrigger1")

...显然在 v2 中,函数名称是像任何其他函数一样从 def test_function 读取的,并且上面的行在上传时会导致读取函数的干扰。

关于python - Azure Functions Python V2 计时器触发器未部署,但在 VSCode 中状态成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75354503/

相关文章:

python - Jython,动态查询多列

visual-studio-code - vscode.workspace.openTextDocument 静默失败

Azure Function App无法将表绑定(bind)到类型 'Microsoft.WindowsAzure.Storage.Table.CloudTable'

azure - 当 'code' 是查询字符串中的参数时,为什么匿名 httptrigger azure 函数会抛出 500 内部服务器错误?

azure-functions - 如何从 azure 应用程序设置或 azure 函数应用程序文件中使用 Serilog 配置?

python - 将 unicode/ascii 字符呈现为 numpy 数组

python - 如何在plotly scattergeo中自定义颜色条?

python - 更改日期范围并循环运行

syntax-error - Visual Studio Code 主题 - 更改 CSS 语法错误字体颜色

visual-studio-code - 如何在 Zen 模式下隐藏 VS Code 中的资源管理器窗口?