feature: In-App Simulation Runner (Backend)
This commit is contained in:
@@ -167,6 +167,23 @@ try
|
||||
builder.Services.Configure<AlertQualityOptions>(
|
||||
builder.Configuration.GetSection(AlertQualityOptions.Section));
|
||||
|
||||
builder.Services.Configure<SimulationOptions>(
|
||||
builder.Configuration.GetSection(SimulationOptions.Section));
|
||||
|
||||
var simulationOptions = builder.Configuration
|
||||
.GetSection(SimulationOptions.Section).Get<SimulationOptions>() ?? new();
|
||||
|
||||
if (simulationOptions.Enabled)
|
||||
{
|
||||
builder.Services.AddHttpClient("simulation-loopback", c =>
|
||||
c.BaseAddress = new Uri(simulationOptions.LoopbackBaseUrl));
|
||||
builder.Services.AddSingleton<ISimulationClientFactory, SimulationClientFactory>();
|
||||
builder.Services.AddSingleton<IScenarioCatalog, ScenarioCatalog>();
|
||||
builder.Services.AddSingleton<SimulationRunner>();
|
||||
builder.Services.AddSingleton<ISimulationRunner>(sp => sp.GetRequiredService<SimulationRunner>());
|
||||
builder.Services.AddHostedService(sp => sp.GetRequiredService<SimulationRunner>());
|
||||
}
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("Dashboard", policy =>
|
||||
@@ -345,6 +362,13 @@ try
|
||||
|| args.Contains("create-admin")
|
||||
|| args.Contains("register-gateway");
|
||||
|
||||
if (simulationOptions.Enabled && !isCliCommand)
|
||||
{
|
||||
Log.Warning(
|
||||
"Simulation mode ENABLED — scenario replay endpoints are exposed. " +
|
||||
"Do not run this configuration against real patient data.");
|
||||
}
|
||||
|
||||
// Demo data — including the seeded demo users with well-known passwords —
|
||||
// must never be created in production. Seeding:EnableDemoData defaults to
|
||||
// true so local development and the existing verification scripts are
|
||||
@@ -360,7 +384,16 @@ try
|
||||
var redis = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>();
|
||||
await DataSeeder.SeedAsync(db, redis);
|
||||
await GatewayRegistrySeeder.SeedAsync(db);
|
||||
await UserSeeder.SeedAsync(db);
|
||||
await UserSeeder.SeedAsync(
|
||||
db,
|
||||
simulationEnabled: simulationOptions.Enabled,
|
||||
simulationRunnerPassword: simulationOptions.RunnerPassword);
|
||||
}
|
||||
else if (simulationOptions.Enabled && !isCliCommand && !app.Environment.IsEnvironment("Testing"))
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await UserSeeder.EnsureSimulationRunnerAsync(db, simulationOptions.RunnerPassword);
|
||||
}
|
||||
|
||||
if (!app.Environment.IsEnvironment("Testing"))
|
||||
|
||||
Reference in New Issue
Block a user