JustScheduler 0.7.1
See the version list below for details.
dotnet add package JustScheduler --version 0.7.1
NuGet\Install-Package JustScheduler -Version 0.7.1
<PackageReference Include="JustScheduler" Version="0.7.1" />
<PackageVersion Include="JustScheduler" Version="0.7.1" />
<PackageReference Include="JustScheduler" />
paket add JustScheduler --version 0.7.1
#r "nuget: JustScheduler, 0.7.1"
#:package JustScheduler@0.7.1
#addin nuget:?package=JustScheduler&version=0.7.1
#tool nuget:?package=JustScheduler&version=0.7.1
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
// .UseSingleInstance()
.ScheduleEvery(TimeSpan.FromSeconds(10))
.RunOnStartup()
// Schedule the tasks by crontab expression (UTC by default).
// Pass isUtc: false to use the scheduler clock's local time zone,
// or a TimeZoneInfo such as TimeZoneInfo.FindSystemTimeZoneById("Europe/Istanbul").
// A 6-field expression adds a leading seconds field: "*/30 * * * * *".
.ScheduleByCron("* * * * *")
// Schedule the task on last day of the month (local time, midnight by default).
// After it runs, the next run is the last day of the following month.
.ScheduleLastDayOfMonth(new TimeOnly(23, 0))
// Schedule the task on last weekday (Mon-Fri) of the month (local time)
.ScheduleLastWorkingDayOfMonth(new TimeOnly(18, 0))
.InjectTrigger()
.Build();
builder
.WithParameterRunner<SomeEventService, SomeEvent>()
// skip this if you want SomeEventService to be constructed
// every time it is scheduled to run
// .UseSingleInstance()
// Run the service with these parameters
// on the application start
.Enqueue(new SomeEvent("Hello world! 1st run."))
.EnqueueRange(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()
// Produce data from your own async producer, called again after each item
// .ScheduleWhen(async ct => await queue.ReceiveAsync(ct))
// 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:
// After a delay, measured by the scheduler clock
trigger.Trigger(data, TimeSpan.FromMinutes(5));
// At an exact instant (recommended: never ambiguous)
trigger.Trigger(data, DateTimeOffset.Parse("2026-11-01T09:00:00+03:00"));
// DateTime is still supported
trigger.Trigger(data, DateTime.UtcNow.AddMinutes(5));
With DateTime, UTC dates are used directly. Local dates are converted to UTC, and dates with
DateTimeKind.Unspecified are interpreted in the scheduler clock's local time zone (see below) 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.
Clock and time zone
Every schedule (ScheduleEvery, ScheduleByCron, the month-end helpers) and every
timed trigger reads time from one TimeProvider. By default it is
TimeProvider.System. A TimeProvider registered in DI is picked up automatically,
or you can set one explicitly, which takes precedence:
services.AddJustScheduler(builder => builder
.UseTimeProvider(myTimeProvider)
.WithRunner<HelloWorldBackgroundService>()
.ScheduleEvery(TimeSpan.FromMinutes(5))
.Build());
Local-time schedules and DateTimeKind.Unspecified trigger dates use the provider's
LocalTimeZone. In tests, FakeTimeProvider from
Microsoft.Extensions.TimeProvider.Testing lets you advance time instantly.
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 | 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. 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. |
-
net10.0
- cronos (>= 0.13.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.14)
-
net8.0
- cronos (>= 0.13.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
-
net9.0
- cronos (>= 0.13.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.22)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.22)
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 |