Azure function time trigger crontab configuration - getting it right

 

Azure function app that uses time trigger needs to be configured correctly otherwise it will behave differently. 

The crontab with 0 */5 * * * * runs as expected. It runs every 5 minutes.

The crontab with 0 5 * * * * configuration. We notice it runs every hour instead of 5 minutes. 



You can investigate further by using NCrontab library with the following codes.


var cron = NCrontab.CrontabSchedule.Parse("5 * * * *");
var start  = DateTime.Now;
var end = DateTime.Now.AddHours(1);

var occurences =  cron.GetNextOccurrences(start, end);
foreach (var occurence in occurences)
{
    Console.WriteLine(occurence);
}

And you will notice only 1 occurrences. 

If you update it to as 0 */5 * * * *, you will typically get 11 occurrences.

var cron = NCrontab.CrontabSchedule.Parse("*/5 * * * *");
var start  = DateTime.Now;
var end = DateTime.Now.AddHours(1);

var occurences =  cron.GetNextOccurrences(start, end);
foreach (var occurence in occurences)
{
    Console.WriteLine(occurence);
}


Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type