Search code examples
c#azureazure-functionsazure-functions-runtime

Parameterize runOnStartup in function.json


I have a Azure function with a timer trigger. I want the function to execute immediately, when I start the project locally for debugging purposes. This can be done by setting the runOnStartup property.

I cannot keep it in production, because it causes the trigger to fire twice every time it is scheduled, so I am trying to use an appropriate setting.

Snippet of function.json:

{
  "schedule": "%TimerSchedule%",
  "runOnStartup": %TimerRunOnStartup%,
  "name": "timer",
  "type": "timerTrigger",
  "direction": "in"
}

Snippet of local.settings.json:

"TimerSchedule": "0 */5 * * * *",
"TimerRunOnStartup": true,

The CRON expression is read from the settings file as expected, but parsing of function.json fails with the following error in case of the Boolean value:

Unexpected character encountered while parsing value: %. Path 'bindings[0].runOnStartup', line 6, position 22.

Is there a way to parametrize a Boolean value in function.json?


Solution

  • AFAIK, it's not possible. "%TimerSchedule%" represents a String so that the percent sign can be resolved and get values from app settings(i.e. local.settings locally).

    While runOnStartUp should be a constant Boolean, only true/false can be recognized by function runtime, so % is invalid. We can't use "%runOnStartUp%" either, as String was not recognized as a valid Boolean.