using Chronos.Server.Configuration;
namespace Chronos.Server.Hosting;
///
/// Chronos.Server --healthcheck: probes the local /health endpoint and exits 0/1, so the container
/// HEALTHCHECK needs no curl/wget in the image.
///
public static class HealthProbe
{
public static async Task RunAsync()
{
try
{
var port = ServerOptions.Load().HttpPort;
using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
using var response = await http.GetAsync(new Uri($"http://127.0.0.1:{port}/health")).ConfigureAwait(false);
return response.IsSuccessStatusCode ? 0 : 1;
}
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or InvalidOperationException)
{
await Console.Error.WriteLineAsync(ex.Message).ConfigureAwait(false);
return 1;
}
}
}