Frank.CronJobs
1.1.7-preview
See the version list below for details.
dotnet add package Frank.CronJobs --version 1.1.7-preview
NuGet\Install-Package Frank.CronJobs -Version 1.1.7-preview
<PackageReference Include="Frank.CronJobs" Version="1.1.7-preview" />
paket add Frank.CronJobs --version 1.1.7-preview
#r "nuget: Frank.CronJobs, 1.1.7-preview"
// Install Frank.CronJobs as a Cake Addin #addin nuget:?package=Frank.CronJobs&version=1.1.7-preview&prerelease // Install Frank.CronJobs as a Cake Tool #tool nuget:?package=Frank.CronJobs&version=1.1.7-preview&prerelease
Frank.CronJobs
This is based on CronQuery, which I am a contributor to. This is built on that code to extend its functionality in experimental ways
Usage
This library is designed to be used with the Microsoft.Extensions.DependencyInjection
library. It is designed to be used
list this in your Program.cs
file:
using Frank.CronJobs;
var services = new ServiceCollection();
services.AddCronJob<MyJob>("0 15 10 * * ?");
var serviceProvider = services.BuildServiceProvider();
await serviceProvider.StartAsync();
This will start the job at 10:15 AM every day. The MyJob
class should implement the ICronJob
interface, and the
ExecuteAsync
method should be implemented. This method will be called every time the cron expression is satisfied.
If you want to stop or modify the job, you can use the IScheuleMaintainer
interface to stop, start, or modify any job at
runtime like this:
var maintainer = serviceProvider.GetRequiredService<IScheduleMaintainer>();
maintainer.Stop<MyJob>();
This will stop the job from running. You can also start it again by calling Start<MyJob>()
. You can also modify the
schedule and timezones of the job by calling SetSchedule<MyJob>("0 15 10 * * ?")
and SetTimeZone<MyJob> ("America/New_York")
respectively.
The job runner is added as a hosted service, so it will run as long as the application is running.
The scenario for editing the schedule at runtime is meant to make it flexible for the user to change the schedule of the job without having to restart the application, or specify the schedule in a configuration file, and so anything that can have the opportunity y to change the schedule at runtime. A service that react to IOptions changes, for example, can look like this:
public class MyService
{
private readonly IOptionsMonitor<MyOptions> _optionsMonitor;
private readonly IScheduleMaintainer _scheduleMaintainer;
public MyService(IOptionsMonitor<MyOptions> optionsMonitor, IScheduleMaintainer scheduleMaintainer)
{
_optionsMonitor = optionsMonitor;
_scheduleMaintainer = scheduleMaintainer;
_optionsMonitor.OnChange(OnOptionsChange);
}
private void OnOptionsChange(MyOptions options)
{
_scheduleMaintainer.SetSchedule<MyJob>(options.CronExpression);
// etc.
}
}
Installation
Install the NuGet package directly from the package manager console:
PM> Install-Package Frank.CronJobs
License
Frank.CronJobs is licensed under the MIT license.
Contributing
Contributions are welcome, please submit a pull request after you create an issue if you have any ideas or find any bugs. Major changes should be discussed in an issue before submitting a pull request. Also, no new dependencies unless discussed and agreed upon in an issue first.
Credits
This library is based on CronQuery, which I am a contributor to. This is built on that code for the basic cron functionality, and some patterns and ideas are borrowed from that project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Frank.CronJobs.Cron (>= 1.1.7-preview)
- Frank.Reflection (>= 1.3.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Frank.CronJobs:
Package | Downloads |
---|---|
Frank.WorkflowEngine
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.9-preview | 96 | 7/11/2024 |
2.0.8-preview | 82 | 6/24/2024 |
2.0.0 | 188 | 2/3/2024 |
1.1.7-preview | 92 | 2/3/2024 |
1.1.6-preview | 126 | 1/29/2024 |
1.1.5-preview | 122 | 1/24/2024 |
1.1.0 | 136 | 1/21/2024 |
1.0.4-preview | 102 | 1/21/2024 |
0.1.0 | 168 | 12/30/2023 |