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

The specified initialization vector (IV) does not match the block size for this algorithm