一个强大的 Cron 任务调度器,适用于 ASP.NET Core 和 .NET Core (2.x-8.x)。使用 fl 简化自主托管和基于 ASP.NET Core 的定时任务的管理。
一个强大的 Cron 任务调度器,适用于 ASP.NET Core 和 .NET Core (2.x-8.x)。使用 fl 简化自主托管和基于 ASP.NET Core 的定时任务的管理。
Note: Pre-release packages are distributed via feedz.io.
Unlock the Power of Simplified Cron Scheduling in Your .NET Core Apps
Are you tired of complex scheduling libraries holding you back from building scalable and efficient applications? Look no further! Introducing CronScheduler, a lightweight and easy-to-use library designed specifically for .NET Core IHost or IWebHost.
Built with the KISS principle in mind, CronScheduler is a simplified alternative to Quartz Scheduler and its alternatives. With CronScheduler, you can easily schedule tasks using cron syntax and operate within any .NET Core GenericHost IHost, making setup and configuration a breeze.
But that's not all! We've also introduced IStartupJob, allowing for async initialization of critical processes before the host is ready to start. This means you can ensure your application is properly initialized and running smoothly, even in complex Kubernetes environments.
Benefits:
IHost or IWebHostJoin the CronScheduler community today and start simplifying your application's scheduling needs!
Please refer to Migration Guide for the upgrade.
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
AspNetCore hosting .NET CLI dotnet add package CronScheduler.AspNetCoreIHost hosting .NET CLI dotnet add package CronScheduler.ExtensionsThis library supports up to 5 seconds job intervals in the Crontab format thank to HangfireIO/Cronos library.
You can use https://crontab-generator.org/ to generated needed job/task schedule.
Cron expression is a mask to define fixed times, dates and intervals. The mask consists of second (optional), minute, hour, day-of-month, month and day-of-week fields. All of the fields allow you to specify multiple values, and any given date/time will satisfy the specified Cron expression, if all the fields contain a matching value.
Allowed values Allowed special characters Comment
┌───────────── second (optional) 0-59 * , - /
│ ┌───────────── minute 0-59 * , - /
│ │ ┌───────────── hour 0-23 * , - /
│ │ │ ┌───────────── day of month 1-31 * , - / L W ?
│ │ │ │ ┌───────────── month 1-12 or JAN-DEC * , - /
│ │ │ │ │ ┌───────────── day of week 0-6 or SUN-SAT * , - / # L ? Both 0 and 7 means SUN
│ │ │ │ │ │
* * * * * *CronScheduler with new Microsoft .NET Core Workers TemplateCronScheduler with AspNetCore applications.There are two ways that options and jobs can be registered within the Scheduler Jobs.
IConfigurationThis job registration is assuming that the name of the job and options name are the same.
services.AddScheduler(ctx =>
{
ctx.AddJob();
});……Then register this service within the Program.cs:
…IStartupJobs to assist with async jobs initialization before the application startsThere are many case scenarios to use StartupJobs for the IWebHost interface or IGenericHost. The most common case scenario is to make sure that the database is created and updated.
This library makes it possible by simply doing the following:
Program.cs file add the following:var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddStartupJob();
builder.Services.AddStartupJob();
var app = builder.Build();
// Configure the HTTP request pipeline.
await app.RunStartupJobsAsync();
await app.RunAsync();In some instances of the application the need for queuing of the tasks is required. In order to enable this add the following in Startup.cs.
services.AddBackgroundQueuedService();Then add sample async task to be executed by the Queued Hosted Service.
public class MyService
{
private readonly IBackgroundTaskQueue _taskQueue;
public MyService(IBackgroundTaskQueue taskQueue)
{
_taskQueue = taskQueue;
}
public void RunTask()
{
_taskQueue.QueueBackgroundWorkItem(async (token)=>
{
// run some task
await Task.Delay(TimeSpan.FromSeconds(10), token);
}});
}
}暂无开放 Issues,或尚未同步最近议题。