how to run yearly recurring job using cron

我只是一个虾纸丫 提交于 2019-12-25 16:49:43

问题


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?


回答1:


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".



来源:https://stackoverflow.com/questions/43933521/how-to-run-yearly-recurring-job-using-cron

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!