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中文網其他相關文章!