greektreat
greektreat

Reputation: 2561

Pause Azure Function until 12am next day

I know you can add spending limit for your azure functions per month, But I need to find a way to limit number of executions for an Azure function per day. The Function I am developing is calling a 3rd party API where we have a limit of 25,000 calls per day. When we reach that limit we get a response "LIMIT_REACH". I want to be able to pause the azure function execution until 12AM the next day. I am using a storage Queue to trigger the Azure Function. I know an option is in the function.json. I can update ["disabled": false] But i will need to set it through programatically. Then I will have to trigger a process to turn on the function again.

Upvotes: 1

Views: 1338

Answers (4)

Troy Witthoeft
Troy Witthoeft

Reputation: 2666

I've made an ask out to the Azure Functions team to introduce a "pause" button for Azure functions. You can see the discussion and possible implementations over here = https://github.com/Azure/azure-functions-host/issues/7888

Upvotes: 1

Jose Roberto Araujo
Jose Roberto Araujo

Reputation: 339

Why don't you use RateLimiter as a tool to limit Function executions? There are a lot of framework that do that. As an example, here is the one:

https://github.com/David-Desmaisons/RateLimiter

I hope that it'll help you!!!

Upvotes: 0

Matt Mason
Matt Mason

Reputation: 2726

Unfortunately there are not any apis to programmatically enable/disable an Azure function at present.

However, you could achieve this in a few ways:

First, upon receiving LIMIT_REACH, have the queue function modify its own function.json to set disabled true - this will trigger a restart after all currently executing functions finish.

Then, at the time you wish to re-enable processing, run a different function to update disabled: true to false:

  • Use a timer trigger with a schedule to run at midnight daily (0 0 0 * * *)

or

  • Use another queue and set the visibility time to schedule when the message becomes visible, upon which time you re-enable the function.

Upvotes: 0

flyte
flyte

Reputation: 1322

Why not keep a flag, or a "next valid execution time" in TableStorage when you have hit the LIMIT_REACH response. Each time the function triggers, interrogate that time and either execute or abort. Update the flag / next execution time when you are able to re-hit that 3rd party API.

Upvotes: 1

Related Questions