我有一个位于连续 Azure Web Job 中的函数,该函数需要每 15 分钟调用一次。
程序中的代码.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();
}
函数中的代码.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 作业的应用服务造成任何类型的性能问题。?
Web 作业有计时器触发器:函数.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://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer