Skip to content

Scheduler

AventusSharp includes a fork of the popular FluentScheduler library. This fork provides enhancements for managing jobs by their names, making it easier to add, remove, and manage scheduled tasks programmatically.

For detailed documentation on FluentScheduler, refer to the official FluentScheduler documentation.


Example: Setting Up a Job in Aventus.cs

Below is an example of how to integrate the job scheduler with AventusSharp, including creating, running, and removing jobs by name:

namespace Demo
{
public static class Aventus
{
public static VoidWithError Init(WebApplication app)
{
VoidWithError initResult = new();
// Initialize various parts of the application
InitData(initResult);
InitHttp(initResult, app);
InitWs(initResult, app);
// Initialize the JobManager
JobManager.Initialize();
int i = 0;
// Add a recurring job named "ping" that runs every 5 seconds
JobManager.AddJob(
job: () =>
{
Console.WriteLine("5sec ping");
i++;
// Remove the job after it has run 5 times
if (i == 5)
{
JobManager.RemoveJob("ping");
}
},
schedule: s => s.ToRunEvery(5).Seconds(),
name: "ping"
);
return initResult;
}
}
}

Key Features of the Forked Version

  • Job Naming: Jobs can be added and managed by a unique name, making it simple to remove or update specific jobs.
  • Ease of Integration: Fully compatible with AventusSharp’s architecture.
  • Custom Scheduling: Supports FluentScheduler’s flexible scheduling options, such as running jobs at fixed intervals or specific times.

This integration is ideal for managing recurring tasks like maintenance, notifications, or background processing. The enhancements in the forked version make managing jobs even more straightforward.