1

The documentation is very clear - set RunOnStartup = false in production. (https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp#example)

However, how do we do that without 'remembering' to change true to false in the code?

I can't see how to pass a config setting from appsettings.json like you can for the Cron String?

e.g.

public async Task DataRetentionAllTenantsAndAccounts([TimerTrigger("%App:DataRetentionAllTenantsAndAccountsCronTrigger%", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
    {
        Console.WriteLine("Started DataRetentionAllTenantsAndAccounts");
        log.LogInformation("Started DataRetentionAllTenantsAndAccounts");
        await _mailMiloManager.DataRetentionAllTenantsAndAccountsAsync();
    }
adudley
  • 902
  • 10
  • 24
  • Does this answer your question? [Azure Functions RunOnStartUp set in configuration rather than at compile time?](https://stackoverflow.com/questions/63719828/azure-functions-runonstartup-set-in-configuration-rather-than-at-compile-time) – Ecstasy Jul 25 '22 at 03:48
  • [Parametrize runOnStartup in function.json](https://stackoverflow.com/questions/51205429/parametrize-runonstartup-in-function-json) and [Azure Function timer configure through app settings](https://stackoverflow.com/questions/45538960/azure-function-timer-configure-through-app-settings) – Ecstasy Jul 25 '22 at 03:52

1 Answers1

0

Here is the code to set RunOnStartup = True in production environment.

    public static void Run([TimerTrigger("%TimerInterval%" 

#if DEBUG 
,RunOnStartup=true // When debugging... run the job as soon as we press debug, no need to wait for the timer. 
#endif

    )]TimerInfo myTimer)

    {

This you can do it using Visual Code. check this SO for complete information.

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15