nightmaregaurav.scheduler
2.0.0
dotnet add package nightmaregaurav.scheduler --version 2.0.0
NuGet\Install-Package nightmaregaurav.scheduler -Version 2.0.0
<PackageReference Include="nightmaregaurav.scheduler" Version="2.0.0" />
paket add nightmaregaurav.scheduler --version 2.0.0
#r "nuget: nightmaregaurav.scheduler, 2.0.0"
// Install nightmaregaurav.scheduler as a Cake Addin #addin nuget:?package=nightmaregaurav.scheduler&version=2.0.0 // Install nightmaregaurav.scheduler as a Cake Tool #tool nuget:?package=nightmaregaurav.scheduler&version=2.0.0
Scheduler
Scheduler is a simple job scheduling framework in C# that allows you to easily define and execute scheduled tasks in the background. This project provides a flexible base class for creating scheduled jobs, a background service for managing job execution, a static api to register your background services dynamically, and an extension method for integrating the scheduler into your application.
Features
- Define custom scheduled jobs by extending the
ScheduledJob
base class. - Enqueue jobs for scheduling using the
ScheduleJobAsync
method. - Background service (
SchedulerService
) manages the execution of scheduled jobs. - Integration with Microsoft.Extensions.DependencyInjection for easy setup.
Getting Started
Install the Scheduler package from NuGet:
dotnet add package nightmaregaurav.scheduler
Create your scheduled job classes by extending the
ScheduledJob
base class. Implement the required methods:public class MyCustomJob : ScheduledJob { public override DateTime GetNextExecutionSchedule() { // Implement your logic to determine the next execution time. } public override Task Execute(IServiceProvider serviceProvider) { // Implement your job's logic here. } }
Add the
SchedulerService
as a hosted service in your application using the extension method:public void ConfigureServices(IServiceCollection services) { // Other service registrations... // Add the scheduler service services.StartScheduler(); }
or in your
program.cs
// Other service registrations... // Add the scheduler service builder.Services.StartScheduler();
Enqueue jobs for scheduling:
var myJob = new MyCustomJob(); SchedulerService.ScheduleJobAsync(myJob);
Run your application, and the scheduler will automatically start executing the scheduled jobs in the background.
Example
- Copy contents of Example folder to a new .NET web application.
- Rename
program-example.cs
toprogram.cs
and uncomment the contents ofprogram.cs
. - Run the application.
- You will see a static scheduled job running every 5 seconds.
- You can send a get request to
/print-time
to schedule a dynamic job that will run every 10 seconds. - You can send a post request to
/send-message
withto
,message
andsecondsDelay
in body to schedule a dynamic job that will run once after the specified delay.
License
Scheduler is released under the MIT License. You can find the full license details in the LICENSE file.
Made with ❤️ by NightmareGaurav.
Open For Contribution
We welcome contributions from the community! If you find any issues or have suggestions for improvements, feel free to open a pull request or issue. Your contributions help make this project better for everyone.
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
- Microsoft.Extensions.Hosting.Abstractions (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.