I have implemented Hangfire in an ASP.NET Core application for sending email(s) as per defined schedule(s). I am creating schedule(s) (CRON expression) and receiving email(s) in the application via different Web API(s) and then sending the email(s) as per scheduled times/ intervals.
I couldn’t find anything in Hangfire to get the description from CRON expression and also to get CRON expression from description/ interval natively. However, I found two nuget packages:
- CronExpressionDescriptor: which gets description from CRON expression.
- CronEspresso: which gets CRON expression from description/ interval.
I have implemented both and it is working as expected.
My code sample:
using CronExpressionDescriptor;
using CronEspresso.NETCore;
...
...
string cronExpression = "* 5 * * * *"; //every 5 minutes
var cronDescription = ExpressionDescriptor.GetDescription(cronExpression);
string cronExpressionAgain = CronGenerator.GenerateMinutesCronExpression(5);
I came to know Hangfire utilizes NCrontab. So, is there any way to achieve above functionalities natively to remove external dependency.