From ef44f88e4e5409bc727cf1387b44c557adcc97d3 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Mon, 14 Oct 2024 13:48:37 -0700 Subject: [PATCH] Set all devices offline on startup. --- ControlR.Web.Server/Extensions/IHostExtensions.cs | 12 +++++++++--- ControlR.Web.Server/Program.cs | 4 ++-- Tests/ControlR.Agent.LoadTester/Program.cs | 7 +------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ControlR.Web.Server/Extensions/IHostExtensions.cs b/ControlR.Web.Server/Extensions/IHostExtensions.cs index e1c313f..fc6f877 100644 --- a/ControlR.Web.Server/Extensions/IHostExtensions.cs +++ b/ControlR.Web.Server/Extensions/IHostExtensions.cs @@ -4,14 +4,20 @@ namespace ControlR.Web.Server.Extensions; public static class HostExtensions { - public static async Task ApplyMigrations(this IHost host) - where TDbContext : DbContext + public static async Task ApplyMigrations(this IHost host) { await using var scope = host.Services.CreateAsyncScope(); - var context = scope.ServiceProvider.GetRequiredService(); + using var context = scope.ServiceProvider.GetRequiredService(); if (context.Database.IsRelational()) { await context.Database.MigrateAsync(); } } + + public static async Task SetAllDevicesOffline(this IHost host) + { + await using var scope = host.Services.CreateAsyncScope(); + await using var context = scope.ServiceProvider.GetRequiredService(); + context.Devices.ExecuteUpdate(calls => calls.SetProperty(d => d.IsOnline, false)); + } } \ No newline at end of file diff --git a/ControlR.Web.Server/Program.cs b/ControlR.Web.Server/Program.cs index f09fedb..9fade4b 100644 --- a/ControlR.Web.Server/Program.cs +++ b/ControlR.Web.Server/Program.cs @@ -218,13 +218,13 @@ app.MapAdditionalIdentityEndpoints(); - app.MapHub("/hubs/viewer"); app.UseOutputCache(); Log.Information("Applying migrations to database at host: {DbHost}", pgHost); -await app.ApplyMigrations(); +await app.ApplyMigrations(); +await app.SetAllDevicesOffline(); await app.RunAsync(); diff --git a/Tests/ControlR.Agent.LoadTester/Program.cs b/Tests/ControlR.Agent.LoadTester/Program.cs index 383d8d3..a3888bf 100644 --- a/Tests/ControlR.Agent.LoadTester/Program.cs +++ b/Tests/ControlR.Agent.LoadTester/Program.cs @@ -26,7 +26,6 @@ Console.WriteLine($"Starting agent count at {startCount}"); var agentCount = 4000; -var connectParallelism = 100; var serverBase = "http://cubey"; var portStart = 42000; var portEnd = 42999; @@ -41,14 +40,10 @@ }; var hosts = new ConcurrentBag(); -var paralellOptions = new ParallelOptions() -{ - MaxDegreeOfParallelism = connectParallelism -}; _ = ReportHosts(hosts, cancellationToken); -await Parallel.ForAsync(startCount, startCount + agentCount, paralellOptions, async (i, ct) => +await Parallel.ForAsync(startCount, startCount + agentCount, async (i, ct) => { if (ct.IsCancellationRequested) {