diff --git a/.github/README.md b/.github/README.md index 4fdfb5d..13d1717 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,2 +1,85 @@ # Pilgaard.CronJobs +![CI](https://github.com/NillerMedDild/Pilgaard.CronJobs/workflows/Release/badge.svg) +[![NuGet](https://img.shields.io/nuget/dt/pilgaard.cronjobs.svg)](https://www.nuget.org/packages/mediatr) +[![NuGet](https://img.shields.io/nuget/vpre/pilgaard.cronjobs.svg)](https://www.nuget.org/packages/mediatr) + + + +Easily schedule jobs to run at specific times, based on Cron expressions. + + + +## Installing Pilgaard.CronJobs + +You should install [Pilgaard.CronJobs with NuGet](https://www.nuget.org/packages/Pilgaard.CronJobs): + + Install-Package Pilgaard.CronJobs + +Or via the .NET Core command line interface: + + dotnet add package Pilgaard.CronJobs + +Or through Package Manager Console. + +## Usage + +Make CronJobs by implementing `ICronJob`: + +```csharp +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("* * * * *"); +} +``` + + + +### Registration + +Register all CronJobs with an `IServiceCollection` instance: + +```csharp +services.AddCronJobs(typeof(Program)); +``` + + + +This will scan the assembly for all classes that implement `ICronJob`, and add them to the container. + +Each `ICronJob` found is then hosted in a `CronBackgroundService`. + + + +### Configuration + +The following options are available for you to customize: + +```csharp +services.AddCronJobs(options => +{ + options.ServiceLifetime = ServiceLifetime.Singleton; + options.CronFormat = CronFormat.IncludeSeconds; + options.TimeZoneInfo = TimeZoneInfo.Utc; +}, typeof(Program)); +``` + + + +## Dependencies + +Please see the [Nuget page](https://www.nuget.org/packages/Pilgaard.CronJobs/) for a handy list of dependencies. + + + +## Thanks to + +The developers of [Cronos](https://github.com/HangfireIO/Cronos) for their excellent Cron expression library.