Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Apr 23, 2022
1 parent a8bd2f8 commit 72f0ab0
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/README.md
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.

0 comments on commit 72f0ab0

Please sign in to comment.