Easily create jobs that run based on Cron expressions.
$ dotnet add package Pilgaard.CronJobsEasily schedule jobs to run at specific times, based on Cron expressions.
With the dotnet CLI:
dotnet add package Pilgaard.CronJobs
Or through Visual Studio or Rider.
Make CronJobs by implementing ICronJob:
public class CronJob : ICronJob
{
public Task ExecuteAsync(CancellationToken cancellationToken = default)
{
// Execute job
return Task.CompletedTask;
}
// This will execute once every minute
public CronExpression CronSchedule => CronExpression.Parse("* * * * *");
}
Register all CronJobs with an IServiceCollection instance:
services.AddCronJobs(typeof(Program));
This will scan the assembly of Program for all classes that implement ICronJob, and add them to the container.
Each ICronJob found is then hosted in a CronBackgroundService.
The developers of Cronos for their excellent Cron expression library.