6

In my dev environment, I have an Azure Functions with 21 functions and the app plan is consumption.

Some functions have a timer trigger and at the end of the process each function sends an email. I have 2 type of timer trigger:

  • run a function every 20 minutes
  • run a function once at a particular time in the night

Every 20 minutes the function is doing what I expect. Great.

The problem I'm facing is with the function that they have to start at a particular time. Basically, they don't start until I open the portal and do something on the Azure Function (for example open the monitor for one of them).

In the code point of view, all functions with the timer trigger are defined like that:

[FunctionName("invoiceMonthlyGeneratorTimer")]
public void Run([TimerTrigger("%Timers:GenerateMonthlyInvoices%")] TimerInfo myTimer)
{
    // ..
}

[FunctionName("invoiceDunningTimer")]
public async Task Run([TimerTrigger("%Timers:DunningTimer%")] TimerInfo timer)
{
    // ...
}

The configuration of the timer is in the settings file like:

"Timers": {
    "DunningTimer": "0 0 4 * * *",
    "GenerateMonthlyInvoices": "0 0 4 * * *"
}

Generally, speaking, this approach was working in dev environment and it is working perfectly in the production environment.

Because each function sends an email, I expect each morning to find in my inbox some emails but it doesn't happen. Then, I open the Azure portal to see the logs and the monitor.

Open the Azure function in the portal.

enter image description here

Open the monitor for a function

enter image description here

Voila, after a couple of seconds, I start to receive the email for all services! In the production environment I don't have all the function I have in dev because I want to test before deploying. In prod the functions are working fine and start at the right time.

If I look at Application Insights, I can find only the logs for the time I opened the monitor.

enter image description here

There is one interesting thing in the log:

Trigger Details: UnscheduledInvocationReason: IsPastDue, OriginalSchedule: 2020-07-24T05:00:00.0000000+00:00

enter image description here

Update

Apparently, you can't have more than a couple of timer triggers in the same Azure Functions. I opened an issue on Github, so if other devs are facing the same. Something similar with HTTP triggers, look this post.

Liam
  • 27,717
  • 28
  • 128
  • 190
Enrico
  • 3,592
  • 6
  • 45
  • 102
  • 1
    Please provide how you setup the timer trigger - most probably in in host.json as well as the Function App invocation logs showing that the function runtime is not working as expected. A working timer trigger results in a log message like `Executing 'Functions.TimerTrigger' (Reason='Timer fired at 2020-07-24T06:00:00.0187114+00:00', Id=b02d2633-c3a4-4050-88ce-c6f8abfb8ed7)` – Sascha Gottfried Jul 24 '20 at 07:59
  • Could you please provide more details of your time trigger function such as when did you set the second function be triggered and when did you open the portal monitor page(The actual execution time of the function). – Frank Borzage Jul 24 '20 at 08:33
  • There are too many functions in your function app, they may interact each other. I met similar problem with this, in that case, the timer trigger functions in one function app and did not work. But when i deploy them to different function apps, they work fine. so could you please deploy your second function to another function app? – Frank Borzage Jul 24 '20 at 09:42
  • In my Azure Functions I have 26 functions and only 7 with the timer trigger. There is no recommendation for Microsoft about it. Sure, I can try but if this is the reason, I'm shocked – Enrico Jul 24 '20 at 10:07
  • Have you tried to deploy them to two function apps? Does it work? – Frank Borzage Jul 27 '20 at 08:29
  • @FrankGong not yet! I'll try to do that today. Also, I want to report this issue to Microsoft – Enrico Jul 27 '20 at 08:47
  • 3
    @FrankGong you are right. I split the function and there are working. It is so annoying! Look my another post https://stackoverflow.com/questions/63115975/azure-functions-with-timer-trigger-unscheduledinvocationreason/ – Enrico Jul 28 '20 at 08:08
  • 2
    I opened an issue on Github, so if other devs have the same problem https://github.com/Azure/Azure-Functions/issues/1666 – Enrico Jul 28 '20 at 08:09
  • Related issue [Why is my python timer trigger function not running at the correct time?](https://stackoverflow.com/questions/61035038/why-is-my-python-timer-trigger-function-not-running-at-the-correct-time) – Liam Jan 28 '21 at 08:56

1 Answers1

1

There are too many functions in your function app, they may interact each other. I met similar problem with this, in that case, the timer trigger functions in one function app and did not work. But when i deploy them to different function apps, they work fine. so you can try to deploy your second function to another function app.

And I suggest you report this problem to Microsoft, they can know more information about this problem, and may have a better solution.

Frank Borzage
  • 6,292
  • 1
  • 6
  • 19
  • 1
    I have this exact issue, but with only one TimerTrigger function in my Function App. The Function App was created in Consumption Mode. Is the Mode the problem? – Joe Jan 20 '23 at 15:36