Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dotnetbots/cronbackgroundservices
`IHostedService` implementation triggered by CRON expressions
https://github.com/dotnetbots/cronbackgroundservices
cron dotnet dotnet-core5
Last synced: about 1 month ago
JSON representation
`IHostedService` implementation triggered by CRON expressions
- Host: GitHub
- URL: https://github.com/dotnetbots/cronbackgroundservices
- Owner: dotnetbots
- Created: 2021-02-08T08:42:32.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-15T23:34:47.000Z (about 1 year ago)
- Last Synced: 2023-11-16T00:29:04.499Z (about 1 year ago)
- Topics: cron, dotnet, dotnet-core5
- Language: C#
- Homepage:
- Size: 62.5 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
[![main](https://github.com/slackbot-net/CronBackgroundServices/workflows/CI/badge.svg)](https://github.com/slackbot-net/CronBackgroundServices/actions) [![NuGet](https://img.shields.io/nuget/v/CronBackgroundServices.svg)](https://www.nuget.org/packages/CronBackgroundServices/)
### CronBackgroundServices
.NET BackgroundService jobs triggered by configured Cron Expressions
### Installation
```bash
$ dotnet add package CronBackgroundServices
```### Usage
Jobs are configured during DI registration:```csharp
services
.AddRecurrer()
.AddRecurrer()
```Each job has to implement `IRecurringAction`. If you want a different TimeZone than UTC you have to override the default interface method `GetTimeZoneId`.
```csharp
public interface IRecurringAction
{///
/// The job to be executed at intervals defined by the Cron expression
///
///
Task Process(CancellationToken stoppingToken);///
/// The cron expression (including seconds) as defined by the Cronos library:
/// See https://github.com/HangfireIO/Cronos#cron-format
/// Ex: Every second: */1 * * * * *
/// Ex: Every minute: 0 */1 * * * *
/// Ex: Every midnight: 0 0 */1 * * *
/// Ex: First of every month 0 0 0 1 * *
///
/// A valid Cron Expression
string Cron { get; }///
/// Optional: The TimeZone in which the Cron expression should be based on.
/// Defaults to UTC (Europe/London or GMT Standard Time)
///
/// NB! When overriding this and targeting versions below .NET 6, use platform specific identifiers
/// If your runtime is .NET 6 or above, it's not required. It will handles the conversion:
/// See https://github.com/dotnet/runtime/pull/49412
///
/// timezoneId
string GetTimeZoneId()
{
return !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Europe/London" : "GMT Standard Time";
}
}
```