0 python timer azure python-3.x azure-functions
我正在编写第一个计时器触发的函数,但在将它们配置为自行运行时遇到问题。为了便于解释,我们只关注其中一个。
函数记录为运行成功,但由于记录,我发现每次函数运行时“myTimer.past_due”都会返回“false”,并且函数逻辑不会启动。
我应该如何设置它才能可靠地返回“true”?
我应该如何设置它,以便它可以通过“测试代码”表单门户运行?
我在这里没有得到什么?是否还有其他定时器需要匹配?
我什至通过在 Azure 中设置新功能应用程序和存储帐户来“将其关闭并再次打开”,以确保我在此过程中没有破坏某些设置。
原理:这是一个ETL函数,通过API连接到第三方平台,并将所需数据插入到azure SQL数据库中。我希望它每天凌晨 1 点运行。对于启动函数脚本,我使用了通过 Microsoft DOC 页面提供的脚本,稍加修改,从这里开始: https: //learn.microsoft.com/pl-pl/azure/azure-functions/functions-bindings-timer ?tabs=python
这是我的“ init.py ”:
import datetime
import logging
import azure.functions as func
from Toggl_Data_Procurement_Function import toggl_script
def main(myTimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
logging.info(f"myTimer.past_due: {myTimer.past_due}")
if myTimer.past_due:
logging.info('Function %s, started by timer trigger, started running at %s', func.Context.function_name, utc_timestamp)
toggl_script.TogglDataProcurementScript(root_directory=str(func.Context.function_directory)).run()
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
logging.info('Function %s, started by timer trigger finished running at %s', func.Context.function_name, utc_timestamp)
Run Code Online (Sandbox Code Playgroud)
这是我的 function.json - 为了调试,我将其设置为每 15 分钟运行一次:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */15 * * * *",
"useMonitor": true
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的 local.settings.json。我编辑了存储帐户和仪器密钥,但它们是从平台的适当应用程序密钥复制的:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_EXTENSION_VERSION": "~3",
"FUNCTIONS_WORKER_RUNTIME": "python",
"APPINSIGHTS_INSTRUMENTATIONKEY": "secret_key_2",
"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=secret_key_2;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/",
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=account_name;AccountKey=secret_key;EndpointSuffix=core.windows.net",
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1970 次 |
| 最近记录: |