ToolWheel.Extensions.JobManager.Conditions 1.0.0

dotnet add package ToolWheel.Extensions.JobManager.Conditions --version 1.0.0
                    
NuGet\Install-Package ToolWheel.Extensions.JobManager.Conditions -Version 1.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="ToolWheel.Extensions.JobManager.Conditions" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ToolWheel.Extensions.JobManager.Conditions" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ToolWheel.Extensions.JobManager.Conditions" />
                    
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 ToolWheel.Extensions.JobManager.Conditions --version 1.0.0
                    
#r "nuget: ToolWheel.Extensions.JobManager.Conditions, 1.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.
#:package ToolWheel.Extensions.JobManager.Conditions@1.0.0
                    
#: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=ToolWheel.Extensions.JobManager.Conditions&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ToolWheel.Extensions.JobManager.Conditions&version=1.0.0
                    
Install as a Cake Tool

ToolWheel.Extensions.JobManager.ExecutionConditions

Pre-execution condition evaluators for the ToolWheel Job Manager. Ships conditions that prevent a job from running when its task limit is reached, when a dependency job is still active, or when the configured rate limit is exceeded.

Package Info

Property Value
Target Framework net8.0; net10.0
NuGet Package ID ToolWheel.Extensions.JobManager.ExecutionConditions
Project Reference ToolWheel.Extensions.JobManager.Abstractions

Auto Configuration

This package ships JobManagerExecutionConditionModule implementing IJobManagerModulDescription. When AddJobManager() scans loaded assemblies at startup it automatically:

  1. Registers IJobRateLimitTracker as a singleton implementation of JobRateLimitTracker.
  2. Adds JobTaskLimiterCondition as an IExecutionCondition.
  3. Adds JobDependencyCondition as an IExecutionCondition.
  4. Adds JobRateLimitCondition as an IExecutionCondition.
  5. Adds JobRateLimitMiddleware to the execution pipeline.

No manual registration is required � referencing the package is sufficient.


Task Limit

Prevents a job from creating new tasks when the configured maximum number of concurrent pending or running tasks is already reached.

Configuration

jobs.Add("import-job", worker.RunImport)
    .Name("Data Import")
    .Enabled()
    .TaskLimit(3); // at most 3 concurrent tasks

A limit of 0 or null means no limit is enforced.

How It Works

  1. When a job is configured with .TaskLimit(count), the JobTaskLimitFeature is applied via IJobExecutionConditionService.Add<JobTaskLimitFeature>().
  2. Before each execution, JobTaskLimiterCondition retrieves the feature and counts active tasks (status Pending or Running) via IJobTaskService.ReadByJob(job, ...).
  3. If the count >= limit, the execution context is set to not ready with the message "Task limit reached".

Job Execution Dependencies

Prevents a job from starting while one or more other jobs still have active (Pending or Running) tasks.

Configuration

jobs.Add("import-job", worker.ImportData)
    .Name("Data Import")
    .Enabled();

jobs.Add("cleanup-job", worker.Cleanup)
    .Name("Cleanup")
    .Enabled()
    .DependsOn("import-job");         // blocked while import-job is active

Multiple dependencies and combinations with other conditions are supported:

jobs.Add("report-job", worker.GenerateReport)
    .Name("Report")
    .Enabled()
    .TaskLimit(1)
    .DependsOn("import-job", "sync-job");

How It Works

  1. When a job is configured with .DependsOn(jobIds), the JobDependencyFeature is applied via IJobExecutionConditionService.Add<JobDependencyFeature>().
  2. Before each execution, JobDependencyCondition iterates the registered dependency job IDs.
  3. For each dependency, it resolves the job instance via IJobService.FindById() and queries active tasks via IJobTaskService.ReadByJob(dep, Pending, Running).
  4. If any dependency has at least one active task, the execution context is set to not ready with the message "A dependent job is still running" and evaluation stops early.

Rate Limiting

Prevents a job from being started too frequently within a rolling time window.

Configuration

jobs.Add("api-sync-job", worker.SyncWithApi)
    .Name("API Sync")
    .Enabled()
    .RateLimit(maxStarts: 10, timeWindow: TimeSpan.FromHours(1));

Combine with other conditions:

jobs.Add("heavy-job", worker.ProcessHeavyWork)
    .Name("Heavy Job")
    .Enabled()
    .TaskLimit(1)
    .RateLimit(maxStarts: 5, timeWindow: TimeSpan.FromMinutes(10));

A maxStarts of 0 or less disables rate limiting for the job. The time window is rolling (continuous), not fixed intervals.

How It Works

  1. When a job is configured with .RateLimit(maxStarts, timeWindow), the JobRateLimitFeature is applied via IJobExecutionConditionService.Add<JobRateLimitFeature>().
  2. Before each execution, JobRateLimitCondition retrieves the feature and calls IJobRateLimitTracker.CanStart(job, feature) to check if the job can be started within the rolling window.
  3. If the number of starts within the window has reached the limit, the execution context is set to not ready with the message "Rate limit reached".
  4. When a task is about to start, JobRateLimitMiddleware records the start time via IJobRateLimitTracker.RecordStart(job).
  5. The tracker automatically purges start times that fall outside the rolling window when evaluating CanStart().

API Reference

Extension Methods (IJobDescriptionBuilder)

Method Description
.TaskLimit(int count) Limits the number of concurrently running tasks for the job.
.DependsOn(params string[] jobIds) Blocks the job while any of the specified jobs are still active.
.RateLimit(int maxStarts, TimeSpan timeWindow) Limits how many times the job can be started within a rolling time window.

Services & Extension Methods

IJobExecutionConditionService Extension Methods
Method Parameters Description
SetTaskLimit(job, count) IJob, int? Stores the task limit for a job; null removes it.
GetTaskLimit(job) IJob Returns the configured task limit or null.
SetDependencies(job, dependsOnJobIds) IJob, IEnumerable<string> Registers dependency job IDs for a job.
GetDependencyJobIds(job) IJob Returns the set of dependency job IDs.
SetRateLimit(job, maxStarts, timeWindow) IJob, int, TimeSpan Configures rate limiting for a job.
GetRateLimit(job) IJob Returns the configured rate-limit feature or null.
IJobRateLimitTracker
Interface Implementation Description
IJobRateLimitTracker JobRateLimitTracker In-memory tracker for job start times; automatically purges expired entries.

Conditions

Type Blocks when
JobTaskLimiterCondition Active task count >= configured limit.
JobDependencyCondition A dependency job has Pending or Running tasks.
JobRateLimitCondition Number of starts within the time window >= configured limit.

Middleware

Type Purpose
JobRateLimitMiddleware Records each job start time for rate-limit accounting.

Features

Type Stores
JobTaskLimitFeature Configured task limit.
JobDependencyFeature Declared dependency job IDs.
JobRateLimitFeature Rate-limit configuration (max starts + time window).
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 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 was computed.  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
1.0.0 107 6/6/2026