1

Here is my function:

using Microsoft.Extensions.Logging;
using System;

namespace ExpDataIngestionBot.AzureFunctions
{
    public static class RecurringFetch
    {
        [FunctionName("RecurringFetch")]
        public static void Run(
            [TimerTrigger("%TriggerIntervalInCRON%", RunOnStartup = true)]
            TimerInfo myTimer, 
            ILogger log, 
            ExecutionContext context)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

It does not execute at startup when ran locally from the Visual Studio instance.

Nishant
  • 2,571
  • 1
  • 17
  • 29
  • Can you show your cron? – Cindy Pau Feb 25 '20 at 05:00
  • RunOnStartup = true work fine on my side. – Cindy Pau Feb 25 '20 at 05:19
  • I see it running now, I am not sure why it did not work earlier. – Nishant Feb 25 '20 at 05:29
  • Is there way to specify its value as true locally and false for the app service instance. – Nishant Feb 25 '20 at 05:31
  • Do you mean change to false in production? – Cindy Pau Feb 25 '20 at 05:33
  • RunOnStartup = true is only used for local debug. You don't need to set in other situations, the default value is false. On normal, the timetrigger attribute is like this: [TimerTrigger("0 */5 * * * *")] – Cindy Pau Feb 25 '20 at 05:34
  • I am looking for a solution where I do not have to modify code each time I have to run it locally. – Nishant Feb 25 '20 at 05:37
  • I tried something like `[TimerTrigger("%TriggerIntervalInCRON%", RunOnStartup = "%RunOnStartup%" == "true")]` and setting `"RunOnStartup" = "true"` in my local.settings.json file, but it did not trigger the function locally on startup. – Nishant Feb 25 '20 at 05:38
  • please dont do that, RunOnStartup only accept bool value(true and false). %% can not be accepted. – Cindy Pau Feb 25 '20 at 05:40
  • Any other ideas on how to set the value of RunOnStartup through a configuration value, so that I can set that configuration to true locally and false in app service? Worst case, I may have to follow the second voted solution on this: https://stackoverflow.com/questions/46556621/what-is-the-simplest-way-to-run-a-timer-triggered-azure-function-locally-once – Nishant Feb 25 '20 at 05:42
  • Yes, you can. Although it looks not good but it work. Please forget about Parametrize of RunOnStartUp, it is not possible. – Cindy Pau Feb 25 '20 at 05:51
  • Is there somewhere I can mention this as a feature request? – Nishant Feb 25 '20 at 06:06
  • Hi, this is the link: [feedback](https://feedback.azure.com/forums/34192--general-feedback) – Cindy Pau Feb 25 '20 at 08:47

0 Answers0