What is Quartz.NET
There are many ways to schedule background jobs, but two are particularly well-known. Quartz and Hangfire. I talked about Hangfire in a recent LinkedIn post. Today we are going to learn about Quartz.
Quartz.NET is used for scheduling jobs with some additional features over Hangfire. CRON triggers, calendar events, and simple events are all supported.
How to use it ?
Install Packages
Create Job
Configure Program.cs
Step 1 : Install Packages
Install following packages from Nuget Package Manager
Microsoft.Data.SqlClient
Microsoft.Extensions.Hosting
Quartz
Quartz.Extensions.Hosting
Quartz.Serialization.Json
Step 2 : Create Job
Step 3 : Configure Program.cs
I have created an extension method for IServiceCollections and called it in Program.cs
await builder.Services.ConfigureQuartzScheduler();
If we want to use our own storage then we can configure SQL otherwise it will automatically use our RAM Job Store.
Using With Identity to group jobs while creating the jobs and triggering them.
Where I have used
WithSimpleSchedule
you can use Calendar/CRON as per your need’s
Thank you for reading my Newsletter , see you in next week :)