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

查看:22
本文介绍了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.

要限制规模,您可以修改应用设置 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT.

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天全站免登陆