Initial version
This commit is contained in:
122
README.md
122
README.md
@@ -1,3 +1,121 @@
|
||||
# EonaCat.FluentTaskScheduler
|
||||
# EonaCat.FluentScheduler
|
||||
|
||||
EonaCat.FluentTaskScheduler
|
||||
**EonaCat.FluentScheduler** is a **task scheduling library for C#**
|
||||
that combines **cron expressions** and **fluent scheduling**.
|
||||
|
||||
It supports persistent tasks, retries, parallel execution, logging, and dynamic task management.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- **Fluent scheduling**: `EveryDayAt`, `EveryWeekOn`, `EveryMonthOn`, `EveryYearOn`
|
||||
- **Cron expressions**: full 6-part syntax with seconds, minutes, hours, day, month, weekday
|
||||
- Supports ranges (`1-5`), lists (`1,2,3`), steps (`*/5`)
|
||||
- **Async-safe and parallel task execution**
|
||||
- **Retry mechanism** for failed tasks with configurable retry count and delay
|
||||
- **Persistent tasks** with automatic restoration on application restart
|
||||
- **Dynamic task management**: remove tasks at runtime
|
||||
- **Task status tracking**: Pending, Running, Success, Failed
|
||||
- **Optional logging** for monitoring task execution
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```csharp
|
||||
Install-Package EonaCat.FluentScheduler
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### 1. Fluent Scheduling
|
||||
|
||||
```csharp
|
||||
using EonaCat.FluentScheduler;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main()
|
||||
{
|
||||
// Daily task at 08:30
|
||||
FluentScheduler.Schedule(async () =>
|
||||
{
|
||||
Console.WriteLine($"Daily task executed at {DateTime.Now}");
|
||||
}).EveryDayAt(8, 30);
|
||||
|
||||
// Weekly task on Monday at 09:00
|
||||
FluentScheduler.Schedule(async () =>
|
||||
{
|
||||
Console.WriteLine($"Weekly task executed at {DateTime.Now}");
|
||||
}).EveryWeekOn(DayOfWeek.Monday, 9, 0);
|
||||
|
||||
Scheduler.Start();
|
||||
Console.ReadKey();
|
||||
Scheduler.Stop();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# 2. Cron Scheduling
|
||||
|
||||
```csharp
|
||||
FluentScheduler.ScheduleCron("Every5Sec", "*/5 * * * * *", async () =>
|
||||
{
|
||||
Console.WriteLine($"Cron task executed every 5 seconds at {DateTime.Now}");
|
||||
});
|
||||
```
|
||||
|
||||
# 3. Logging and Retry
|
||||
```csharp
|
||||
Scheduler.SetLogger(Console.WriteLine);
|
||||
```
|
||||
|
||||
# 4. Dynamic Task Removal
|
||||
```csharp
|
||||
// Remove a task by name
|
||||
Scheduler.RemoveTask("Every5Sec");
|
||||
```
|
||||
|
||||
# 5. Task Status Tracking
|
||||
```csharp
|
||||
foreach (var task in Scheduler.GetAllTasks())
|
||||
{
|
||||
Console.WriteLine($"{task.Name}: Status={task.Status}, NextRun={task.NextRun}, LastRun={task.LastRun}, LastError={task.LastError}");
|
||||
}
|
||||
```
|
||||
|
||||
# 6. Retry Mechanism
|
||||
|
||||
* Default: 3 retries, 5 seconds delay
|
||||
* Configurable via RetryCount and RetryDelaySeconds on ScheduledTask objects
|
||||
|
||||
## Cron Expression Format
|
||||
|
||||
```csharp
|
||||
<second> <minute> <hour> <day> <month> <weekday>
|
||||
```
|
||||
|
||||
* – any value
|
||||
|
||||
*/n – every n units
|
||||
|
||||
x-y – range
|
||||
|
||||
x,y,z – list of values
|
||||
|
||||
### Examples:
|
||||
|
||||
"0 30 8 * * 1" → Every Monday at 08:30:00
|
||||
|
||||
"*/10 * * * * *" → Every 10 seconds
|
||||
|
||||
### Persistence
|
||||
|
||||
* Tasks are automatically saved to tasks.json on disk.
|
||||
* On restart, tasks are restored automatically.
|
||||
* Action mapping is handled internally via registered task names.
|
||||
Reference in New Issue
Block a user