简体   繁体   中英

how to run yearly recurring job using cron

Hangfire is using ncrontab to run recurring job.

Does this below contab run every weekly Monday at 12 am for only 2017 ?

0 0 * * 1

How can I make sure it runs only for 2017 or every year?

Hangfire uses NCrontab library. As you could see, this lib provides a way to rapidly test its own functionality. Just open C# Interactive window in Visual Studio and paste a code like below:

#r "C:\Users\YOUR_USER\.nuget\packages\ncrontab\3.3.0\lib\netstandard1.0\NCrontab.dll"
using NCrontab;
var s = CrontabSchedule.Parse("0 0 * * 1");
var start = new DateTime(2000, 1, 1);
var end = start.AddYears(12);
var occurrences = s.GetNextOccurrences(start, end);
Console.WriteLine(string.Join(Environment.NewLine, 
    from t in occurrences
    select $"{t:ddd, dd MMM yyyy HH:mm}"));

Another way is to use online crontab visualizer. For example: cron.schlitt.info .

Both tools give the same result: your cron expression means "run each Monday forever".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM