NOBS.JobSystem.Hosting
1.1.1
dotnet add package NOBS.JobSystem.Hosting --version 1.1.1
NuGet\Install-Package NOBS.JobSystem.Hosting -Version 1.1.1
<PackageReference Include="NOBS.JobSystem.Hosting" Version="1.1.1" />
<PackageVersion Include="NOBS.JobSystem.Hosting" Version="1.1.1" />
<PackageReference Include="NOBS.JobSystem.Hosting" />
paket add NOBS.JobSystem.Hosting --version 1.1.1
#r "nuget: NOBS.JobSystem.Hosting, 1.1.1"
#:package NOBS.JobSystem.Hosting@1.1.1
#addin nuget:?package=NOBS.JobSystem.Hosting&version=1.1.1
#tool nuget:?package=NOBS.JobSystem.Hosting&version=1.1.1
NOBS.JobSystem
A lightweight, persistence-agnostic, dependency-injection friendly job scheduling system for .NET applications. It provides CRON-based scheduling, job chaining, manual triggering, and a persistent execution history with an optional Blazor-based monitoring UI.
Key Features
- Fluent Configuration: A clean, expressive API for registering jobs and their dependencies.
- Hybrid Configuration: Define job schedules and storage settings in
appsettings.jsonwhile keeping job logic in code. - Pluggable Storage: Persist job history to SQL Server, MongoDB, SQLite, JSON files, or a custom provider.
- Stable Job Identity: Use the
[JobName]attribute to assign a persistent identifier to your jobs, preventing history loss when you refactor class names. - CRON Scheduling: Define recurring jobs using standard CRON expressions.
- Job Chaining: Create powerful workflows by specifying continuation jobs on success or failure.
- Global Error Handling: Configure a specific job to run whenever any unhandled exception occurs.
- DI-First Design: Jobs are resolved from the service container, giving them full access to all registered application services.
- Trimming and AOT Friendly: Designed to work out-of-the-box with trimmed and AOT-compiled applications.
- Manual Triggering: Force any registered job to run immediately via the monitoring UI or programmatically.
- Optional Monitoring UI: A clean, lightweight Blazor UI to monitor job statuses.
Packages
The system is distributed across multiple NuGet packages for modularity:
| Package | Description |
|---|---|
NOBS.JobSystem |
The core library containing the job orchestrator and scheduling logic. |
NOBS.JobSystem.Hosting |
A meta-package for easily installing and configuring the UI endpoint. |
NOBS.JobSystem.UI |
The Blazor-based monitoring UI. (Typically consumed via the Hosting package) |
NOBS.JobSystem.Stores.SqlServer |
Persistence provider for Microsoft SQL Server. |
NOBS.JobSystem.Stores.MongoDb |
Persistence provider for MongoDB. |
NOBS.JobSystem.Stores.SQLite |
Persistence provider for SQLite. |
NOBS.JobSystem.Stores.JsonFile |
Persistence provider for a local JSON file. |
Usage Guide
1. Configuration via AppSettings
You can manage your job schedules and storage settings externally using appsettings.json. This allows you to change schedules without recompiling the application.
appsettings.json
{
"JobSystem": {
"PollingFrequency": "00:01:00",
"Jobs": {
"report-processor": "0 2 * * *",
"db-cleanup": "0 4 * * 0"
},
"Storage": {
"ConnectionString": "Server=.;Database=MyJobDb;Trusted_Connection=True;TrustServerCertificate=True;",
"SchemaName": "scheduler",
"HistoryTableName": "JobHistory",
"PollingFrequency": "00:00:30"
}
}
}
Program.cs
using NOBS.JobSystem.Execution;
using NOBS.JobSystem.Stores.SqlServer;
var builder = WebApplication.CreateBuilder(args);
// Register Jobs
builder.Services.AddScoped<ProcessDailyReportsJob>();
builder.Services.AddScoped<DatabaseCleanupJob>();
// Add Job System with Configuration
builder.Services
.AddJobSystem(builder.Configuration.GetSection("JobSystem"), registry =>
{
// Schedules defined in appsettings.json will override the code defaults.
registry.AddJob<ProcessDailyReportsJob>("0 1 * * *");
registry.AddJob<DatabaseCleanupJob>();
})
.UseSqlServer(builder.Configuration.GetSection("JobSystem:Storage"));
2. Fluent Configuration
Alternatively, you can configure everything in code.
builder.Services
.AddJobSystem(registry =>
{
registry.AddJob<ProcessDailyReportsJob>("0 1 * * *")
.OnSuccess<ArchiveOldReportsJob>()
.OnError<ReportGenerationFailedJob>();
registry.AddJob<ArchiveOldReportsJob>();
registry.AddJob<ReportGenerationFailedJob>();
})
.UseJsonFile(options =>
{
options.FilePath = "Data/job_history.json";
options.PollingFrequency = TimeSpan.FromSeconds(30);
});
Defining Jobs
Jobs are simple classes that implement IJob.
[JobName("report-processor")]
public class ProcessDailyReportsJob(ILogger<ProcessDailyReportsJob> logger) : IJob
{
public async Task<JobExecutionResult> ExecuteAsync(CancellationToken cancellationToken)
{
logger.LogInformation("Starting daily report generation...");
// Logic...
return JobExecutionResult.Success();
}
}
Building From Source
To build the project from source, clone the repository and run the .NET build command from the root directory.
git clone https://github.com/scippo97sensibleproductions/NOBS.JobSystem.git
cd NOBS.JobSystem
dotnet build -c Release
Contributing
Contributions are welcome. Please follow these standard steps:
- Fork the repository.
- Create a new feature branch (
git checkout -b feature/your-feature-name). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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
- NOBS.JobSystem.UI (>= 1.1.1)
-
net6.0
- NOBS.JobSystem.UI (>= 1.1.1)
-
net8.0
- NOBS.JobSystem.UI (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.