【问题标题】:WebJobs - How to configure TimeTrigger RunOnStartup in appsettings?WebJobs - 如何在 appsettings 中配置 TimeTrigger RunOnStartup?
【发布时间】:2022-08-03 19:58:51
【问题描述】:

文档非常清楚-在生产中设置 RunOnStartup = false. (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp#example)

但是,如果不“记住”在代码中将 true 更改为 false,我们如何做到这一点?

我看不到如何像 Cron 字符串那样从 appsettings.json 传递配置设置?

例如

public async Task DataRetentionAllTenantsAndAccounts([TimerTrigger(\"%App:DataRetentionAllTenantsAndAccountsCronTrigger%\", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
    {
        Console.WriteLine(\"Started DataRetentionAllTenantsAndAccounts\");
        log.LogInformation(\"Started DataRetentionAllTenantsAndAccounts\");
        await _mailMiloManager.DataRetentionAllTenantsAndAccountsAsync();
    }

标签: c# azure-webjobs azure-webjobssdk timer-trigger


【解决方案1】:

这是在生产环境中设置RunOnStartup = True 的代码。

    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)

    {

您可以使用 Visual Code 来做到这一点。检查此SO 以获取完整信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多