2

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.

VSO
  • 11,546
  • 25
  • 99
  • 187
  • 1
    Of course you can have two time trigger in one function app. What do you mean Trigger A is defined 'first'? – Cindy Pau Nov 03 '20 at 14:24
  • 1
    @BowmanZhu a single function inside a function app can't have more than one trigger, I understand that is the question asked. – Peter Bons Nov 03 '20 at 14:33
  • 2
    You cannot have a single function with two timer trigger. You can have 2 functions, each with their own timer trigger, and have them call a shared method. That shared logic can expose a boolean flag indicating it is running. If so, an other caller can skip invocation. That would be your desired situation if I understand correctly. – Peter Bons Nov 03 '20 at 14:34
  • Thanks guys, trying now. – VSO Nov 03 '20 at 14:49

1 Answers1

3

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.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27