Azure功能-防止多次调用 [英] Azure Function - Guarding against Multiple invocation

查看:63
本文介绍了Azure功能-防止多次调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计时器触发器上具有Azure功能.我已经看到它的多个实例同时运行.有什么办法可以防止多次调用吗?我不希望它一直运行到上一次调用完成,即使我按了Azure门户上的播放"按钮以执行该功能.例如,当我按下门户上的运行"按钮时,以下内容似乎两次启动,以为已经有一个实例正在运行.

I have an Azure function on timer trigger. I have seen multiple instance of it running at the same time. Is there a way I can guard against multiple invocations? I don't want it to run until the previous invocation has completed even if I press the play button on Azure portal for function.For instance the below seems to be started twice when I pressed the run button on portal, think there was already an instance running.

2019-02-19T04:25:16  Welcome, you are now connected to log-streaming service.
2019-02-19T04:25:23.353 [Info] Function started (Id=aacaf548-79f1-49ec-8614-e638302b8368)
2019-02-19T04:25:26.639 [Info] Function started (Id=f4abe10c-f2bf-447b-bef7-efe3499420c6)

推荐答案

您可能能够实现的一种方法是使函数代码同步(阻塞),并将扩展范围限制为仅一个实例.这样,每次执行都会成为阻塞调用.

One way you might be able to achieve this is making function your code synchronous (blocking) and limiting the scale to one instance only. That way, each execution will be a blocking call.

要限制比例,您可以修改应用设置

To limit the scale, you could modify the App Setting WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT.

尽管[Info]日志中的请求ID不同,但这不一定意味着请求到达了两个不同的实例.我相信,如果您的代码是异步的,则同一个应用程序实例可以并行处理多个请求.

Although the request IDs are different in the [Info] logs, it may not necessarily mean that the requests went to two different instances. I believe, if your code is asynchronous, the same app instance can process multiple requests in parallel.

这篇关于Azure功能-防止多次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆