Search code examples
c#azuretriggersncron

Two Timer Triggers on Azure Function With Params


We have two timer triggers an Azure function - Trigger A and Trigger B. If Trigger A is defined "first", it runs and Trigger B doesn't. Likewise, if Trigger B is defined first, it runs and Trigger A does not.

This leads to two questions:

  1. Can an Azure function have two timer triggers? I can't find anything in the documentation. Closest thing I found is a SO answer implying that this is impossible.
  2. What is a good solution to this problem given that comma-delimited NCRONTAB expression as per the official docs does not cut it here due to the different params?

We are at a point where we are tempted to change the timer triggers to API triggers and have a redundant function app on a timer call the endpoint with different params.


Solution

  • Update:

    As Peter Bons mentioned, 'call a shared method'.

    Original Answer:

    Can an Azure function have two timer triggers? I can't find anything in the documentation. Closest thing I found is a SO answer implying that this is impossible.

    If you are talking about azure function app, then it is possiable.

    But if you are talking about single azure function, then you can not put two trigger in one function.

    For example, below works well:

    enter image description here

    What is a good solution to this problem given that comma-delimited NCRONTAB expression as per the official docs does not cut it here due to the different params?

    CRON expressions cannot represent all use cases, so sometimes it is necessary to divide the code into two functions in a function app.

    If you want a 'dynamic' CRON, you can do something like below and change the ralated value:

    {
      "bindings": [
        {
          "name": "myTimer",
          "type": "timerTrigger",
          "direction": "in",
          "schedule": "%test%"
        }
      ]
    }
    

    enter image description here

    Above is change the value on portal, you can also set the environment variable. The value gets from env var.