JustScheduler 0.6.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package JustScheduler --version 0.6.2
                    
NuGet\Install-Package JustScheduler -Version 0.6.2
                    
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="JustScheduler" Version="0.6.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JustScheduler" Version="0.6.2" />
                    
Directory.Packages.props
<PackageReference Include="JustScheduler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JustScheduler --version 0.6.2
                    
#r "nuget: JustScheduler, 0.6.2"
                    
#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.
#:package JustScheduler@0.6.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JustScheduler&version=0.6.2
                    
Install as a Cake Addin
#tool nuget:?package=JustScheduler&version=0.6.2
                    
Install as a Cake Tool

JustScheduler

.NET Core Background Scheduler that supports multiple backends for 21st century! Built on HostedServices and supports dependency injection that is already present on your application!

Sample project can be found at samples\JustScheduler.SampleWeb directory.

Simple Job

public class HelloWorldBackgroundService : IJob {
  private readonly DbContext db;

  public HelloWorldBackgroundService(DbContext db) {
		this.db = db;
  }

  public async Task Run() {
		Console.WriteLine("Hello world!");
  }
}

Generic Event Job

public class SomeEventService : IJob<SomeEvent> {
  private readonly DbContext db;

  public SomeEventService(DbContext db) {
		this.db = db;
  }

  public async Task Run(SomeEvent e) {
		Console.WriteLine(e.message);
  }
}

Generic Data Source

public class RabbitMqPooler : IDataSource<SomeEvent> {
  private readonly RabbitMqService rabbitMqService;

  public SomeEventService(RabbitMqService rabbitMqService) {
		this.rabbitMqService = rabbitMqService;
  }

  public async IAsyncEnumarable<SomeEvent> Run(CancellationToken ct) {
		while(!ct.IsCancellationRequested) {
			var data = await es.PoolData(ct);
			yield return data;
		}
  }
}

Each injected data source gets a dedicated scope for its enumeration. With AddDataSource<MySource>(), the scheduler creates and owns the source. When its enumeration ends, the scheduler disposes the enumerator, then the source, then its scope. Async disposal is preferred over synchronous disposal.

The factory overload leaves source ownership with the factory or DI container:

.AddDataSource(sp => sp.GetRequiredService<MySource>())

For a factory that constructs a new source outside DI, transfer ownership explicitly:

.AddDataSource(sp => new MySource(sp.GetRequiredService<MyDependency>()), ownsSource: true)

Only transfer ownership of newly constructed, unshared instances. Sources should honor the cancellation token in Run, so pending reads can finish during shutdown. Long-running sources should create short scopes for individual database operations rather than retaining a scoped database context for their entire lifetime.

Startup configuration

public void ConfigureServices(IServiceCollection services) {
  services.AddJustScheduler(builder => {
		builder
			.WithRunner<HelloWorldBackgroundService>()

			// skip this if you want HelloWorldBackgroundService to be constructed
			// every time it is scheduled to run
			// .UseSingletonPattern()

			.ScheduleEvery(TimeSpan.FromSeconds(10))
			.ScheduleOnce()

			// Schedule the tasks by crontab expression.
			.ScheduleByCron("* * * * *")

			// Schedule the task on last day of the month
			.ScheduleLastDayOfMonth(hour: 0, minute: 0, seconds: 0)

			// Schedule the task on last working day of the month
			.ScheduleLastWorkingDayOfMonth(hour: 0, minute: 0, seconds: 0)

			.InjectTrigger()
			.Build();

		builder
			.WithParameterRunner<SomeEventService, SomeEvent>()

			// skip this if you want SomeEventService to be constructed
			// every time it is scheduled to run
			// .UseSingletonPattern()

			// Run the service with these parameters
			// on the application start
			.ScheduleOnce(new SomeEvent("Hello world! 1st run."))
			.ScheduleOnce(new SomeEvent[] {
				new SomeEvent("Hello world! 2st run."),
				new SomeEvent("Hello world! 3rd run.")
			})

			// Injects IJobTrigger<SomeEventService, SomeEvent> to DI
			// so you can pass data to the background worker
			// from your controller or services!
			.InjectTrigger()

			// Initializes RedisDataSource and listens for incoming job
			// you can add multiple datasources per background service!
			.AddDataSource<RedisDataSource>()

			.Build();
		);
	});

	// the rest of the configure function
}

Timed triggers

Use .InjectTimedTrigger() when building a parameterized job, then resolve ITimedJobTrigger<MyJob, MyData> to schedule an item:

trigger.Trigger(data, DateTime.UtcNow.AddMinutes(5));

UTC dates are used directly. Local dates are converted to UTC, and dates with DateTimeKind.Unspecified are interpreted in the server's local time zone for compatibility. Prefer explicit UTC values when the caller and server may have different time zones. Dates already due are eligible to run immediately.

Distant dates are supported through bounded, cancellable waits. Pending schedules recheck the UTC clock at intervals of at most one minute, so clock corrections are reflected at the next check. Actual execution also depends on job availability.

Inside a controller

public class SomeController : Controller {
  private readonly IJobTrigger<SomeEventService, SomeEvent> someEventService;
  private readonly IJobTrigger<SomeParameterlessBackgroundService> helloWorldTrigger;

  public SomeController(
		IJobTrigger<SomeEventService, SomeEvent> someEventService,
		IJobTrigger<HelloWorldBackgroundService> helloWorldTrigger
  ) {
		this.helloWorldTrigger = helloWorldTrigger;
		this.someEventService = someEventService;
  }

  [HttpGet("/postjob")]
  public bool PostJob(string message) {
		SomeEventService.Run(new SomeEvent(message)); // it queues the event to run 
																									// on the background!
  }

  [HttpGet("/checkresults")]
  public bool PostJob(string message) {
		SomeParameterlessService.Run(); // it queues the event to run
																		// on the background!
  }
}

Running tests

Tests use xUnit.net v3 4.x with Microsoft Testing Platform v2 and require the .NET 10 SDK. Run the suite from the repository root:

dotnet test

To run a specific test class:

dotnet test --project tests/JustScheduler.Tests/JustScheduler.Tests.csproj --filter-class 'JustScheduler.Tests.TimedTriggerTests'

License

© 2019 Burak Tamturk

Released under the MIT LICENSE

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.8.0 92 11/10/2026
0.7.1 109 10/30/2026
0.7.0 99 10/30/2026
0.6.2 99 10/28/2026
0.6.1 97 10/28/2026
0.6.0 732 11/11/2025
0.5.4 289 11/5/2025
0.5.3 258 8/1/2025
0.5.2 292 2/6/2025
0.5.1 320 11/19/2024
0.5.0 243 11/18/2024
0.4.0 1,676 11/17/2023
0.3.6 539 1/17/2023
0.3.5 1,165 11/8/2022
0.3.3 348 9/18/2022
0.3.2 623 11/10/2021
0.3.1 1,005 11/11/2020
0.3.0 689 11/11/2020
0.2.1 687 9/21/2020
0.2.0 751 5/13/2020
Loading failed