[英]Does a timer-triggered Azure function execute if an instance of the function is already executing?
I have an Azure Function App with the [TimerTrigger(...)]
attribute, which is scheduled to execute every morning.我有一个带有
[TimerTrigger(...)]
属性的 Azure Function 应用程序,计划每天早上执行。
Suppose you manually execute the function via the Function Menu Blade -> Code + Test -> Test/Run, as shown at the bottom of this message.假设您通过 Function 菜单刀片 -> 代码 + 测试 -> 测试/运行手动执行 function,如该消息底部所示。 What happens if this manual execution of the function is still running when the time specified in the
TimerTrigger
attribute arrives?如果在
TimerTrigger
属性中指定的时间到达时,手动执行 function 仍在运行,会发生什么情况?
You can run the same azure function at the same time.您可以同时运行相同的 azure function。 You can add a bool if you want to prevent the execution of the azure function if it is currently running:
如果要阻止 azure function 当前正在运行,则可以添加一个布尔值:
public class AzureFunction()
{
private static bool _isRunning = false;
[FunctionName("Function1")]
public async Task Run([TimerTrigger("0 30 9 * * *")]
if (_isRunning)
{
//an instance is already running, lets not continue
return;
}
_isRunning = true;
//work is being done
//after work is done
_isRunning = false;
}
Say you have a Timer that goes off every minute, but your code takes 2 minutes to run.假设您有一个每分钟都会关闭的计时器,但您的代码需要 2 分钟才能运行。 The timer will kick off every minute regardless of if the previous run is done or not.
无论之前的运行是否完成,计时器都会每分钟启动一次。
If you set your TimerTrigger to run at a daily time, a manual run will not interrupt or cause an issue to your daily run but you can still do a manual run during your timed trigger .如果您将 TimerTrigger 设置为每天运行,手动运行不会中断或导致日常运行出现问题,但您仍然可以在定时触发期间进行手动运行。 Example of the one above will run every day at 9:30am.
上述示例将在每天上午 9:30 运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.