A dynamic scaling extension for Hangfire that provides real-time queue monitoring and automatic server scaling capabilities.
$ dotnet add package DynaScaleHangfireA dynamic scaling extension for Hangfire that provides real-time server and queue monitoring with dynamic worker count management and actual server restart capabilities.
dotnet add package DynaScaleHangfire
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();
var app = builder.Build();
// Automatically creates wwwroot directory and adds static files middleware
app.UseHangfireDynaScaleWithStaticFiles();
Navigate to /dynamic-scaling to access the DynaScale dashboard.
public sealed record DynaScaleOptions
{
public int MaxWorkerCountPerQueue { get; init; } = 100;
}
MaxWorkerCountPerQueue: Maximum number of workers that can be set for any queue (default: 100)DynaScaleHangfire provides real-time server management with actual server restart capabilities:
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.
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
GET /dynamic-scaling/servers - Get all active server-queue configurations grouped by machinePOST /dynamic-scaling/servers/{serverName}/queues/{queueName}/set-workers - Update worker count for a specific server-queue{
"workerCount": 5,
"applyToAllServers": false
}
workerCount: The new worker count to setapplyToAllServers: If true, applies the worker count to all servers for this queuepublic 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
}
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
}
public sealed record SetWorkersRequest
{
public int WorkerCount { get; init; }
public bool ApplyToAllServers { get; init; }
}
Unlike other solutions that only update configuration, DynaScaleHangfire actually:
dotnet restore
dotnet build
dotnet pack -c Release
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)