Skip to content

Commit

Permalink
Set all devices offline on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Oct 14, 2024
1 parent ed4f8e2 commit ef44f88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
12 changes: 9 additions & 3 deletions ControlR.Web.Server/Extensions/IHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ namespace ControlR.Web.Server.Extensions;

public static class HostExtensions
{
public static async Task ApplyMigrations<TDbContext>(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<TDbContext>();
using var context = scope.ServiceProvider.GetRequiredService<AppDb>();
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<AppDb>();
context.Devices.ExecuteUpdate(calls => calls.SetProperty(d => d.IsOnline, false));
}
}
4 changes: 2 additions & 2 deletions ControlR.Web.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@

app.MapAdditionalIdentityEndpoints();


app.MapHub<ViewerHub>("/hubs/viewer");

app.UseOutputCache();

Log.Information("Applying migrations to database at host: {DbHost}", pgHost);
await app.ApplyMigrations<AppDb>();
await app.ApplyMigrations();
await app.SetAllDevicesOffline();

await app.RunAsync();

Expand Down
7 changes: 1 addition & 6 deletions Tests/ControlR.Agent.LoadTester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,14 +40,10 @@
};

var hosts = new ConcurrentBag<IHost>();
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)
{
Expand Down

0 comments on commit ef44f88

Please sign in to comment.