DynaScaleHangfire 1.0.36

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

DynaScaleHangfire

A dynamic scaling extension for Hangfire that provides real-time server and queue monitoring with dynamic worker count management and actual server restart capabilities.

Features

  • Real Server Restart: Actually stop and restart Hangfire servers with new worker counts
  • Queue-based Worker Management: Update worker counts for specific queues on individual servers
  • Job Processing Safety: Automatically pause job processing before server restart
  • Active Server Monitoring: Only display active servers (last heartbeat within 1 minute)
  • Queue Aggregation: Combine duplicate queues within the same server
  • Modern UI: Horizontal layout with improved queue management interface
  • Machine-based Grouping: Group servers by machine name for better organization
  • RESTful API: Simple HTTP endpoints for server-queue management
  • Web Dashboard Integration: Seamless integration with Hangfire dashboard
  • Automatic Static Files: JavaScript files are automatically copied to build output

Installation

NuGet Package

dotnet add package DynaScaleHangfire

Manual Installation

  1. Clone this repository
  2. Build the project
  3. Reference the built assembly in your project

Quick Start

1. Add Services

using Hangfire.DynaScale.Extensions;
using Hangfire.DynaScale.Models;

var builder = WebApplication.CreateBuilder(args);

// Add DynaScale services with custom options
builder.Services.AddHangfireDynaScale(new DynaScaleOptions
{
    MaxWorkerCountPerQueue = 50
});

// Or use default options
builder.Services.AddHangfireDynaScale();

2. Configure Middleware

var app = builder.Build();

// Automatically creates wwwroot directory and adds static files middleware
app.UseHangfireDynaScaleWithStaticFiles();

3. Access Dashboard

Navigate to /dynamic-scaling to access the DynaScale dashboard.

Configuration

DynaScaleOptions

public sealed record DynaScaleOptions
{
    public int MaxWorkerCountPerQueue { get; init; } = 100;
}
  • MaxWorkerCountPerQueue: Maximum number of workers that can be set for any queue (default: 100)

How It Works

DynaScaleHangfire provides real-time server management with actual server restart capabilities:

Server Restart Process

  1. Pause Job Processing: Temporarily pause new job assignments to the target server
  2. Wait for Completion: Wait for currently processing jobs to complete
  3. Stop Server: Remove the server from Hangfire's storage
  4. Restart Server: Create a new BackgroundJobServer with updated worker count
  5. Resume Processing: New jobs can be assigned to the restarted server

Queue Management

  • Queue Aggregation: Duplicate queues within the same server are combined
  • Worker Count Calculation: Total worker count is calculated per queue per server
  • Active Server Filtering: Only servers with recent heartbeats are displayed

Dashboard Features

  • Horizontal Layout: Queue information and controls are displayed side by side
  • Real-time Updates: Automatic page refresh after worker count changes
  • Server Status: Active/inactive status with last heartbeat information
  • Machine Grouping: Servers are grouped by machine name for better organization

Automatic wwwroot Creation

This package automatically creates a wwwroot directory in your project if it doesn't exist when using UseHangfireDynaScaleWithStaticFiles(). This ensures that Hangfire's dashboard static files are properly served.

Project Structure

DynaScaleHangfire/
├── Controllers/
│   └── DynaScaleController.cs          # REST API endpoints
├── Extensions/
│   ├── ApplicationBuilderExtensions.cs # Middleware configuration
│   └── ServiceCollectionExtensions.cs  # DI configuration
├── Models/
│   ├── DynaScaleOptions.cs            # Configuration options
│   ├── ServerInfoModel.cs             # Data models
│   └── SetWorkersRequest.cs           # API request model
├── Services/
│   ├── HangfireServerManager.cs       # Core server management logic
│   └── IHangfireServerManager.cs      # Service interface
├── Pages/
│   └── DynamicScalingPage.cs          # Dashboard page
├── build/
│   └── DynaScaleHangfire.targets      # MSBuild targets for file copying
└── wwwroot/
    └── js/
        └── dynamic-scaling.js         # Frontend JavaScript

API Endpoints

  • GET /dynamic-scaling/servers - Get all active server-queue configurations grouped by machine
  • POST /dynamic-scaling/servers/{serverName}/queues/{queueName}/set-workers - Update worker count for a specific server-queue

Request Body for Set Workers

{
  "workerCount": 5,
  "applyToAllServers": false
}
  • workerCount: The new worker count to set
  • applyToAllServers: If true, applies the worker count to all servers for this queue

Data Models

ServerInfo

public sealed record ServerInfo
{
    public string ServerName { get; init; }        // Machine name
    public bool IsActive { get; init; }            // Server activity status
    public DateTime LastHeartbeat { get; init; }   // Last heartbeat time
    public List<QueueInfo> Queues { get; init; }   // Queue configurations
}

QueueInfo

public sealed record QueueInfo
{
    public string ServerName { get; init; }        // Actual server name
    public string QueueName { get; init; }         // Queue name
    public int CurrentWorkerCount { get; init; }   // Current worker count
    public int MaxWorkerCount { get; init; }       // Maximum worker count
}

SetWorkersRequest

public sealed record SetWorkersRequest
{
    public int WorkerCount { get; init; }
    public bool ApplyToAllServers { get; init; }
}

Key Features Explained

Real Server Restart

Unlike other solutions that only update configuration, DynaScaleHangfire actually:

  • Stops the existing BackgroundJobServer
  • Creates a new BackgroundJobServer with updated settings
  • Ensures job processing safety during the restart process

Queue Aggregation

  • Combines duplicate queue names within the same server
  • Calculates total worker count for each unique queue
  • Maintains individual server separation

Active Server Filtering

  • Only displays servers with heartbeats within the last minute
  • Automatically hides inactive or disconnected servers
  • Provides real-time server status monitoring

Modern UI

  • Horizontal layout for better space utilization
  • Side-by-side queue information and controls
  • Automatic page refresh after changes
  • Responsive design for different screen sizes

Development

Prerequisites

  • .NET 7.0 SDK or later
  • Visual Studio 2022 or VS Code
  • Hangfire storage provider (SQL Server, Redis, PostgreSQL, etc.)

Building

dotnet restore
dotnet build

Creating NuGet Package

dotnet pack -c Release

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Contact

Acknowledgments

  • Built on top of Hangfire
  • Uses Hangfire's monitoring APIs for real-time data
  • Community contributions and feedback
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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.36 89 7/4/2025
1.0.35 94 7/4/2025
1.0.34 89 7/4/2025
1.0.33 93 7/4/2025
1.0.32 106 7/4/2025
1.0.31 123 7/4/2025
1.0.30 115 7/4/2025
1.0.29 142 7/3/2025
1.0.28 126 7/3/2025
1.0.27 135 7/3/2025
1.0.26 125 7/3/2025
1.0.25 129 7/3/2025
1.0.24 132 7/3/2025
1.0.23 134 7/3/2025
1.0.22 126 7/3/2025
1.0.21 142 6/30/2025
1.0.20 128 6/30/2025
1.0.19 123 6/30/2025
1.0.18 121 6/30/2025
1.0.17 126 6/30/2025
1.0.16 125 6/30/2025
1.0.15 204 6/30/2025 1.0.15 is deprecated because it is no longer maintained and has critical bugs.
1.0.14 202 6/30/2025 1.0.14 is deprecated because it is no longer maintained and has critical bugs.
1.0.13 205 6/30/2025 1.0.13 is deprecated because it is no longer maintained and has critical bugs.
1.0.12 205 6/30/2025 1.0.12 is deprecated because it is no longer maintained and has critical bugs.
1.0.11 206 6/30/2025 1.0.11 is deprecated because it is no longer maintained and has critical bugs.
1.0.10 208 6/30/2025 1.0.10 is deprecated because it is no longer maintained and has critical bugs.
1.0.9 176 6/27/2025 1.0.9 is deprecated because it is no longer maintained and has critical bugs.
1.0.8 117 6/27/2025 1.0.8 is deprecated because it is no longer maintained and has critical bugs.
1.0.7 123 6/27/2025 1.0.7 is deprecated because it is no longer maintained and has critical bugs.
1.0.6 123 6/27/2025 1.0.6 is deprecated because it is no longer maintained and has critical bugs.
1.0.4 162 6/27/2025 1.0.4 is deprecated because it is no longer maintained and has critical bugs.
1.0.3 174 6/26/2025 1.0.3 is deprecated because it is no longer maintained and has critical bugs.
1.0.2 288 6/26/2025 1.0.2 is deprecated because it is no longer maintained and has critical bugs.