adudley
adudley

Reputation: 944

WebJobs - How to configure TimeTrigger RunOnStartup in appsettings?

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();
    }

Upvotes: 1

Views: 634

Answers (1)

SaiSakethGuduru
SaiSakethGuduru

Reputation: 2439

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.

Upvotes: 1

Related Questions