Search code examples
c#azureazure-functionsazure-functions-runtimetimer-trigger

Azure function TimerTrigger only running once


This is my Function.Json

{   "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.28",   "configurationSource": "attributes",   "bindings": [
    {
      "type": "timerTrigger",
      "schedule": "*/5 * * * * *",
      "useMonitor": true,
      "runOnStartup": false,
      "name": "myTimer"
    }   ],   "disabled": false,   "scriptFile": "../bin/PullRequest.dll",   "entryPoint": "PullRequest.PullRequest.Run" }

This is my actual function:

[FunctionName("PullRequest")]
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, ILogger log)
{
     if (myTimer.IsPastDue)
     {
         log.LogInformation("Timer is running late!");
     }
     log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}

When I tried to run this function on Azure portal then it only run once and stops.

this is the log of the Azure Funciton: enter image description here

I rerun it and now it only running once.:enter image description here


Solution

  • Time trigger will automatically execute as per CORN expression i.e. in your case this function will execute every five seconds and If you run it from azure portal it will run only once. If you want to check timings of last executions you can go to Monitor tab and check timings . I have executed this locally and its working as expected enter image description here