LANCommander/LANCommander.Server/Startup/Beacon.cs
Pat Hartl 4fc1a45f88 Add support for horizontal scaling
This commit adds support to allow the LANCommander server to scale horizontally. Multiple instances of the application can be deployed for load-balancing purposes. This will require a load balancer in front of the instances, as well as either MySQL or PostgreSQL and a Redis cache.
2026-07-22 20:19:31 -05:00

27 lines
No EOL
1.1 KiB
C#

using LANCommander.SDK;
using LANCommander.SDK.Interceptors;
using LANCommander.SDK.Services;
using LANCommander.Server.Services;
using LANCommander.Server.Services.Abstractions;
namespace LANCommander.Server.Startup;
public static class Beacon
{
public static async Task StartBeaconAsync(this WebApplication app)
{
var settingsProvider = app.Services.GetRequiredService<SettingsProvider<Settings.Settings>>();
var beaconService = app.Services.GetRequiredService<BeaconClient>();
var interceptor = app.Services.GetRequiredService<IBeaconMessageInterceptor>();
var election = app.Services.GetRequiredService<ICoordinatorElection>();
beaconService.Initialize();
beaconService.AddBeaconMessageInterceptor(interceptor);
if (!await election.TryAcquireAsync())
return;
if (settingsProvider.CurrentValue.Server.Beacon.Enabled)
await beaconService.StartBeaconAsync(settingsProvider.CurrentValue.Server.Beacon.Port, settingsProvider.CurrentValue.Server.Beacon.Address, settingsProvider.CurrentValue.Server.Beacon.Name);
}
}