Lightweight job runner for ASP.NET Core.
For release notes refer to CHANGELOG.
Package Manager (Visual Studio):
Install-Package CronQuery
.NET CLI:
dotnet add package CronQuery
Jobs are created by implementing the interface IJob
.
public class MyJob : IJob
{
public async Task RunAsync()
{
// Do your magic
}
}
Jobs are registered in the app's Startup
class.
public void ConfigureServices(IServiceCollection services)
{
services.AddCronQuery(Configuration.GetSection("CronQuery"));
services.AddTransient<MyFirstJob>();
services.AddTransient<MySecondJob>();
services.AddTransient<MyThirdJob>();
}
public void Configure(IApplicationBuilder app, IApplicationLifetime appLifetime)
{
app.UseCronQuery()
.Enqueue<MyFirstJob>()
.Enqueue<MySecondJob>()
.Enqueue<MyThirdJob>()
.StartWith(appLifetime);
}
Jobs are registered using the ASP.NET Core dependency injection. This means that is possible to use dependency injection in your jobs.
Schedule your jobs using cron expressions of six fields to a specific timezone. Also, turn on or off CronQuery or a specific job by setting the Running
property to true
or false
respectively.
Save the configuration in your appsettings.json
like the example below:
-
MyFirstJob
: Runs every second on every day, except Sunday. -
MySecondJob
: Runs every day at 2:00 A.M. -
MyThirdJob
: Runs every second between 2:00 P.M. and 6:59 P.M. only on Saturday every 15 days.
{
"CronQuery": {
"Running": true,
"Timezone": "E. South America Standard Time",
"Jobs": [
{
"Name": "MyFirstJob",
"Running": true,
"Cron": "* * * * * 1-6"
},
{
"Name": "MySecondJob",
"Running": true,
"Cron": "0 0 2 * * *"
},
{
"Name": "MyThirdJob",
"Running": true,
"Cron": "* * 14-18 * * 6/15"
}
]
}
}
Whenever you save the
appsettings.json
CronQuery immediately assumes the new configuration.
If you have any questions, detect a bug or need a new feature, please, fell free to open a new issue on GitHub.