nightmaregaurav.scheduler 2.0.0

dotnet add package nightmaregaurav.scheduler --version 2.0.0                
NuGet\Install-Package nightmaregaurav.scheduler -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nightmaregaurav.scheduler" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nightmaregaurav.scheduler --version 2.0.0                
#r "nuget: nightmaregaurav.scheduler, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. Install the Scheduler package from NuGet:

    dotnet add package nightmaregaurav.scheduler
    
  2. 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.
        }
    }
    
  3. 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();
    
  4. Enqueue jobs for scheduling:

    var myJob = new MyCustomJob();
    SchedulerService.ScheduleJobAsync(myJob);
    
  5. 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 to program.cs and uncomment the contents of program.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 with to, message and secondsDelay 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 159 3/5/2024
1.0.1 178 8/17/2023
1.0.0 170 8/16/2023