Azure 计时器触发器:每小时的 Cron 表达式

Azure Timer Trigger: Cron expression for every hour on the hour

每小时整点的 cron 表达式是什么? 我试过这个'0 0 *? * *' 但它抛出了一个错误 我有一个 Azure 函数计时器触发器

下面的表达式每分钟运行一次。

public static void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, TraceWriter log)

这是我在尝试“0 0 * ? * * *”和“0 0 * ? * *”时收到的错误

[11/22/2018 12:45:29 AM] A ScriptHost error has occurred [11/22/2018 12:45:29 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Currencies.Run'. Microsoft.Azure.WebJobs.Extensions: The schedule expression '0 0 * ? * * *' was not recognized as a valid cron expression or timespan string. [11/22/2018 12:45:29 AM] Error indexing method 'Currencies.Run' [11/22/2018 12:45:29 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Currencies.Run'. Microsoft.Azure.WebJobs.Extensions: The schedule expression '0 0 * ? * * *' was not recognized as a valid cron expression or timespan string.

编辑:尝试使用"0 0 * * * *"doc强调使用六个字段。

Azure Functions uses the NCronTab library to interpret CRON expressions. A CRON expression includes six fields:

{second} {minute} {hour} {day} {month} {day-of-week}


Azure 应该根据 doco 使用 NCrontab 库,但测试表明并非如此! 所以每个小时都使用 "0 * * * *"

这是要验证的 LINQPad 脚本:

var s = CrontabSchedule.Parse("0 * * * *");
var start = new DateTime(2000, 1, 1);
var end = start.AddYears(1);
var occurrences = s.GetNextOccurrences(start, end);
occurrences.Dump();

[这需要引入 NCrontab nuget 包]

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

"Azure Functions uses the NCronTab library to interpret CRON expressions"