简体   繁体   English

异步定时器触发功能

[英]Async Timer Triggered Function

Is it possible to create a function on a TimerTrigger, that will run asynchronously? 是否可以在TimerTrigger上创建一个异步运行的函数? In other words, a function that will not cause the trigger to wait for completion, before scheduling the next execution? 换句话说,在调度下一次执行之前,一个不会导致触发器等待完成的函数?

We have a scenario where we need to schedule a function execution every 5 seconds. 我们有一个场景,我们需要每5秒安排一次函数执行。 Most executions take less than a second to complete, but occasionally, they can take longer (more than 5 seconds). 大多数执行都需要不到一秒的时间才能完成,但偶尔也会花费更长的时间(超过5秒)。 In those situations, we still want our 5-second schedule to kick in, even though that would cause parallel executions. 在这些情况下,我们仍然希望我们的5秒计划启动,即使这会导致并行执行。

According to this : 根据这个

If your function execution takes longer than the timer interval, another execution won't be triggered until after the current invocation completes. 如果函数执行时间超过计时器间隔,则在当前调用完成之后才会触发另一次执行。 The next execution is scheduled after the current execution completes. 在当前执行完成后安排下一次执行。

What I'm looking for, is a possible way to avoid delaying the next execution. 我正在寻找的是一种避免延迟下一次执行的可能方法。

I think adding a queue would likely address your issue and is the most common async processing pattern. 我认为添加队列可能会解决您的问题,并且是最常见的异步处理模式。 Instead of the timer function processing the request have the request passed on as a message to a storage queue when the timer trigger is executed. 当执行定时器触发器时,请求不是处理定时器功能,而是将请求作为消息传递给存储队列。 A second function then processes the actual request without impacting any execution times on the timer function. 然后,第二个函数处理实际请求,而不会影响计时器功能的任何执行时间。

So essentially timer trigger -> message -> queue trigger . 所以基本上是定时器触发器 - >消息 - >队列触发器。 More details on azure function storage queue triggers can be found at https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#trigger---example 有关azure函数存储队列触发器的更多详细信息,请访问https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#trigger---example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM