Azure 定时器触发函数“.past_due”returns false
Azure timer triggered function ".past_due" returns false
我正在编写我的第一个定时器触发函数,但我在将它们配置为 运行 时遇到了问题。为了便于解释,让我们只关注一个。
函数成功记录为 运行 但由于记录,我发现每次函数都是 运行 "myTimer.past_due" returns "false" 和函数逻辑没有启动。
我应该如何设置才能使其 return 可靠地显示为“真”?
我应该如何设置它才能运行通过“测试代码”表单门户?
我没有得到什么?是否还有其他必须匹配的定时器?
我什至通过在 Azure 中设置新的功能应用程序和存储帐户来“关闭并再次打开它”,以确保我没有在我的途中破坏一些设置。
原理:这个是ETL函数,通过API连接到第三方平台,将需要的数据插入天蓝色的SQL数据库。我希望每天凌晨 1 点 运行。对于启动函数脚本,我使用了通过 Microsoft DOC 页面提供的脚本,稍作修改,来自此处:https://docs.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)
这是我的 function.json - 为了进行调试,我将其设置为每 15 分钟 运行:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */15 * * * *",
"useMonitor": true
}
]
}
这是我的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",
}
}
属性past_due
表示您的定时触发功能是否被及时调用。如果你的定时器触发函数被及时调用(工作正常),它将是“假”。只有当定时器触发器函数被调用的时间晚于预定时间时,past_due
才会为“true”。可以参考这个document.
所以你不能把代码放在if myTimer.past_due:
下面,你应该像下面截图那样写代码:
针对您 How should i set it up so it would runvia "test-code" form portal?
的问题。定时触发函数应该根据cron表达式自动执行。我们不应该运行它在门户网站上手动。
我正在编写我的第一个定时器触发函数,但我在将它们配置为 运行 时遇到了问题。为了便于解释,让我们只关注一个。
函数成功记录为 运行 但由于记录,我发现每次函数都是 运行 "myTimer.past_due" returns "false" 和函数逻辑没有启动。
我应该如何设置才能使其 return 可靠地显示为“真”?
我应该如何设置它才能运行通过“测试代码”表单门户?
我没有得到什么?是否还有其他必须匹配的定时器?
我什至通过在 Azure 中设置新的功能应用程序和存储帐户来“关闭并再次打开它”,以确保我没有在我的途中破坏一些设置。
原理:这个是ETL函数,通过API连接到第三方平台,将需要的数据插入天蓝色的SQL数据库。我希望每天凌晨 1 点 运行。对于启动函数脚本,我使用了通过 Microsoft DOC 页面提供的脚本,稍作修改,来自此处:https://docs.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)
这是我的 function.json - 为了进行调试,我将其设置为每 15 分钟 运行:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */15 * * * *",
"useMonitor": true
}
]
}
这是我的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",
}
}
属性past_due
表示您的定时触发功能是否被及时调用。如果你的定时器触发函数被及时调用(工作正常),它将是“假”。只有当定时器触发器函数被调用的时间晚于预定时间时,past_due
才会为“true”。可以参考这个document.
所以你不能把代码放在if myTimer.past_due:
下面,你应该像下面截图那样写代码:
针对您 How should i set it up so it would runvia "test-code" form portal?
的问题。定时触发函数应该根据cron表达式自动执行。我们不应该运行它在门户网站上手动。