Python 开发人员可以使用 Azure Functions 创建轻量级、可扩展且高效的无服务器应用程序。在这篇文章中,我们将重点关注触发器。
触发器是 Azure Functions 的基础。它们决定如何调用函数。每个函数必须有一个触发器,并且触发器类型决定了该函数可用的数据负载。 Azure 支持各种触发器,包括:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS) def http_trigger(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') return func.HttpResponse("Hello world from HTTP trigger")
参数:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.timer_trigger(schedule="0 */5 * * * *", arg_name="myTimer", run_on_startup=False, use_monitor=False) def timer_trigger(myTimer: func.TimerRequest) -> None: if myTimer.past_due: logging.info('The timer is past due!') logging.info('Python timer trigger function executed.')
参数:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.blob_trigger(arg_name="myblob", path="blobname", connection="BlobStorageConnectionString") def BlobTrigger(myblob: func.InputStream): logging.info(f"Python blob trigger function processed blob" f"Name: {myblob.name}" f"Blob Size: {myblob.length} bytes")
参数:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS) def http_trigger(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') return func.HttpResponse("Hello world from HTTP trigger")
参数:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.timer_trigger(schedule="0 */5 * * * *", arg_name="myTimer", run_on_startup=False, use_monitor=False) def timer_trigger(myTimer: func.TimerRequest) -> None: if myTimer.past_due: logging.info('The timer is past due!') logging.info('Python timer trigger function executed.')
参数:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.blob_trigger(arg_name="myblob", path="blobname", connection="BlobStorageConnectionString") def BlobTrigger(myblob: func.InputStream): logging.info(f"Python blob trigger function processed blob" f"Name: {myblob.name}" f"Blob Size: {myblob.length} bytes")
参数:
import azure.functions as func import datetime import json import logging app = func.FunctionApp() @app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS) def http_trigger(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') return func.HttpResponse("Hello world from HTTP trigger")
参数:
以上是Azure Functions 与 Python:触发器的详细内容。更多信息请关注PHP中文网其他相关文章!