0

我有一个位于连续 Azure WebJob 中的函数,并且该函数需要每 15 分钟调用一次。

Program.cs 中的代码

    static void Main()
    {
        var config = new JobHostConfiguration();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost(config);
        host.Call(typeof(Functions).GetMethod("StartJob"));
        host.RunAndBlock();
    }

Function.cs 中的代码

    [NoAutomaticTrigger]
    public static void StartJob()
    {
        checkAgain:
        if (DateTime.Now.Minute % 15 == 0 && DateTime.Now.Second == 0)
        {
            Console.WriteLine("Execution Started on : " + DateTime.Now);
            //Execute some tasks
            goto checkAgain;
        }
        else
        {
            goto checkAgain;
        }
    }

我的方法正确吗?由于这是一个无限循环,此代码块是否会对托管此 Web 作业的 AppService 产生任何类型的性能问题。?

4

1 回答 1

-1

webjobs有定时器触发器: function.json

{
    "schedule": "0 */5 * * * *",
    "name": "myTimer",
    "type": "timerTrigger",
    "direction": "in"
}

C#

public static void Run(TimerInfo myTimer, ILogger log)
{
    if (myTimer.IsPastDue)
    {
        log.LogInformation("Timer is running late!");
    }
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}" );  
}

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer

于 2019-08-20T16:06:47.930 回答