mirror of
https://github.com/Stone-Red-Code/RemoteExec.git
synced 2026-09-04 09:06:20 +02:00
Add load balancing
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
using RemoteExec.Server.Hubs;
|
||||
|
||||
namespace RemoteExec.Server.Services;
|
||||
|
||||
public class MetricsBroadcastService(IHubContext<RemoteExecutionHub> hubContext, ILogger<MetricsBroadcastService> logger) : BackgroundService
|
||||
{
|
||||
private readonly TimeSpan _broadcastInterval = TimeSpan.FromSeconds(2);
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
logger.LogInformation("Metrics broadcast service started");
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(_broadcastInterval, stoppingToken);
|
||||
|
||||
await RemoteExecutionHub.BroadcastMetricsAsync(hubContext);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Expected when service is stopping
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error broadcasting metrics");
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogInformation("Metrics broadcast service stopped");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user