Search code examples
azurecronazure-functions

Azure function: make schedule cron a variable in function.json


I have an Azure function. For codes, I only have init.py and function.json.

function.json is like the following:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "timer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 1 */12 * * *"
    }
  ]
}

Is it possible to make the "12" in schedule a variable (eg. called IntervalVariable) and get it from init.py?

So that it becomes

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "timer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 1 */{IntervalVariable} * * *"
    }
  ]
}

Solution

  • I just realized this can be done easily with %IntervalVariable% and add a key-value pair in Azure application settings.

    {
      "scriptFile": "__init__.py",
      "bindings": [
        {
          "name": "timer",
          "type": "timerTrigger",
          "direction": "in",
          "schedule": "0 1 */%IntervalVariable% * * *"
        }
      ]
    }
    

    And then add

    key: IntervalVariable
    value: 12
    

    in Azure function application settings.