2

I have a set of Azure Functions, which are developing in Visual Studio.

There is one TimerTrigger function, which is disabled by default with DisableAttribute. This results "disabled" attribute to be set to true on Azure portal. Once special condition is met, another function is triggered, which updates the TimerTrigger function.json file with "disabled": false. This launches the TimerTrigger.

But when the other condition is met, the function.json of TimerTrigger updated with "disabled": true, which takes no effect, TimerTrigger still fires.

The update of function.json is performed like described here How to Enable/Disable Azure Function programmatically.

I've read through multiple issues on GitHub, still no answer. I see the following workarounds:

  1. Try modifying host.json file with functions list updated each time. But I couldn't find any sample of changing host.json file. Also, I assume it is not very good approach, as all functions are reloaded during such update, and in documentation there is advice use this approach only for local debugging. https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#functions.
  2. Bind DisableAttribute on AppSetting. But I find the process of updating app.settings to sophisticated. Change Azure website app settings from code.
  3. Reconsidering architectural approach.

The main purpose of TimerTrigger - is to get enabled and start calling some server when it's down (ConnectionValidator). As soon as server is OK - disabling TimerTrigger, and continuing usual workflow.

Any ideas about this? Maybe there is some other way to workaround this?

BumbleBee
  • 97
  • 1
  • 8

1 Answers1

2

I would not be changing function.json for this case. It feels hacky.

Either change the application setting, or change environment variable with the same name instead, which should have the same effect.

Or maybe even keep firing timer trigger all the time, and check a precondition as the first action of timer function. Quit immediately if no action is needed.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107