就像标题所说,我有一个 Azure 函数“weekly_monitoring”,它设置为每周执行多个 python 脚本。尽管被禁用,它仍在继续执行。此外,它连续执行多次。我不知道这是怎么可能的,因为我已经通过 UI 以及触发器(cron 计时器)禁用了该功能。另外,当我查看 Azure 函数监视器时,它显示执行事件为零。
这是初始化文件代码:
import azure.functions as func
import os
import datetime
import logging
import sys
import importlib.util
# Azure function timer. To alter timer cadence see function.json file
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)
def run_script(script_name):
script_path = os.path.join(os.path.dirname(__file__), f'{script_name}')
s = importlib.util.spec_from_file_location(script_name, script_path)
m = importlib.util.module_from_spec(s)
sys.modules[s.name] = m
s.loader.exec_module(m)
def batch_execution(file_list):
exceptions = [] #store errors
for file in file_list:
try:
run_script(file)
except Exception as e:
exceptions.append(e)
else:
print('Success')
return exceptions
# list of scripts running in function, if adding new script add to list.
file_list = ['file_one.py',
'file_two.py',
'file_three.py',
'file_four.py',
'file_five.py']
batch_execution(file_list)
下面是触发函数的代码:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"useMonitor": true,
"runOnStartup": false,
"direction": "in",
"schedule": "0 5 * * MON"
}
],
"disabled": true
}
最佳答案
正如在 OP 的评论中发现的那样,之前执行 Azure 函数(预禁用)生成的消息似乎被困在中间电子邮件提供商中,并在死后传递。
关于python-3.x - 尽管被禁用,Azure Function 仍在继续执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76949059/