Shiju Samuel
Shiju Samuel

Reputation: 1591

Azure Function - Guarding against Multiple invocation

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)

Upvotes: 3

Views: 2111

Answers (1)

Ankit Kumar
Ankit Kumar

Reputation: 508

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.

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.

Upvotes: 3

Related Questions