.netazureazure-functionscrontrigger

Azure Function timer is running twice and when I log onto the Azure portal


I have a Timed Function App in Azure that is scheduled to run at 22:00 daily. However, it appears to run at 21:59 and also at 22:00, consistently every day. It also appears to run at random when I am logged into the Azure portal checking the logs.

Here's an example of the timestamps of the duplicate entries I am getting:

enter image description here

I have searched the web but have found no working solution.

Here's the signature of the app, which takes about 20s to complete:

[FunctionName("Function1")]
public static void Run([TimerTrigger("0 0 22 * * *", RunOnStartup = false)]TimerInfo myTimer, TraceWriter log)
{
   // My code
}

And here's my local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXX",
    "AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXX",
    "type": "timerTrigger",
    "schedule": "0 0 22 * * *",
    "useMonitor": false,
    "SQLConn": "Server=tcp:XXX.database.windows.net,1433;Initial Catalog=XXX;Persist Security Info=False;User ID=XXX;Password=XXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
  },
  "disabled": false
}

Can anyone help me out?

Also, the "Monitor" section in Azure's functions show nothing unusual.


Solution

  • I took a look at our internal logs for your function app (thanks for sharing the name!), and I see the following:

    2018-03-02 14:43:50.4977179: Function 'DemoAzureFunction.Function1.Run' is configured to run on startup. Executing now.
    2018-03-02 14:44:01.7856855: Function 'DemoAzureFunction.Function1.Run' updated status: Last='2018-03-02T14:43:48.6103583+00:00', Next='2018-03-02T22:00:00.0000000+00:00', LastUpdated='3/2/2018 2:43:48 PM'
    

    So it looks to me that at one point you had RunOnStartup = true in your function configuration. When configured this way, accessing the portal can trigger the timer to run immediately (separate from the configured schedule) since the portal interaction will wake up your function app.