2026-07-16 20:53:56 +00:00
|
|
|
using Heimdall.Agent.Services;
|
2026-07-18 14:09:32 +00:00
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
2026-07-16 19:09:28 +00:00
|
|
|
|
2026-07-18 14:09:32 +00:00
|
|
|
var builder = WebApplication.CreateSlimBuilder(args);
|
2026-07-16 20:53:56 +00:00
|
|
|
|
2026-07-18 14:09:32 +00:00
|
|
|
// HTTP clients
|
2026-07-16 20:53:56 +00:00
|
|
|
builder.Services.AddHttpClient("Central", client =>
|
|
|
|
|
{
|
|
|
|
|
client.Timeout = TimeSpan.FromSeconds(10);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-18 14:02:40 +00:00
|
|
|
builder.Services.AddHttpClient("IpResolver", client =>
|
|
|
|
|
{
|
|
|
|
|
client.Timeout = TimeSpan.FromSeconds(5);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-18 14:09:32 +00:00
|
|
|
// Agent services
|
2026-07-16 20:53:56 +00:00
|
|
|
builder.Services.AddSingleton<AgentState>();
|
|
|
|
|
builder.Services.AddHostedService<AgentRegistrationService>();
|
2026-07-16 19:09:28 +00:00
|
|
|
|
2026-07-18 14:09:32 +00:00
|
|
|
// Health checks — used by Docker HEALTHCHECK
|
|
|
|
|
builder.Services.AddHealthChecks()
|
|
|
|
|
.AddCheck<AgentHealthCheck>("agent_health", tags: ["ready"]);
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Health endpoint (port 5001 is mapped in Dockerfile)
|
|
|
|
|
app.MapHealthChecks("/healthz", new HealthCheckOptions
|
|
|
|
|
{
|
|
|
|
|
Predicate = _ => true,
|
|
|
|
|
ResultStatusCodes =
|
|
|
|
|
{
|
|
|
|
|
[HealthStatus.Healthy] = StatusCodes.Status200OK,
|
|
|
|
|
[HealthStatus.Degraded] = StatusCodes.Status200OK,
|
|
|
|
|
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await app.RunAsync();
|