-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8bd2f8
commit 72f0ab0
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |