【发布时间】:2019-12-05 12:12:49
【问题描述】:
我想在每天晚上 9 点使用 Timer 触发器触发 HttpTrigger 函数。是否可以在 Azure 函数中用于 python?
我无法理解如何实现它?有没有办法实现上述场景?
请检查以下代码。
HttpTrigger 功能代码
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
logging.info(name)
if name:
return func.HttpResponse(f"Hello {name}!")
else:
return func.HttpResponse(
"Please pass a name on the query string or in the request body",
status_code=400
)
TimerTrigger 功能代码:-
import datetime
import logging
import requests
import azure.functions as func
def main(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)
url = '<My URL>'
PARAMS = {"name": "Akshay"}
response_decoded_json = requests.post(url=url, params =PARAMS)
print(response_decoded_json.text)
logging.info("Result is :- ")
logging.info(response_decoded_json.text)
请查看以下错误日志图片:-
【问题讨论】:
-
关于这个问题的任何更新?
-
@GeorgeChen 我在 TimerTrigger 函数中遇到了
The timer is past due!问题。
标签: python python-3.x azure-functions azure-functions-runtime azure-function-app