| | | 1 | | using ArturRios.Data.Relational.Core.Interfaces; |
| | | 2 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 3 | | using Microsoft.EntityFrameworkCore; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Query.HealthChecks; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Verifies the database connection (UC-30, FR-HC-03) by issuing a trivial read through the |
| | | 9 | | /// repository abstraction. If the query completes the connection is healthy; any failure (the |
| | | 10 | | /// database being unreachable throws on execution) is treated as unhealthy rather than |
| | | 11 | | /// propagated, so the detailed health check can still report the aggregate status (AF-30c). |
| | | 12 | | /// </summary> |
| | 4 | 13 | | public class DatabaseHealthCheck(IAsyncReadOnlyRepository<Role, long> roleReader) : IServiceHealthCheck |
| | | 14 | | { |
| | 3 | 15 | | public string ServiceName => "Database"; |
| | | 16 | | |
| | | 17 | | public async Task<bool> IsHealthyAsync() |
| | | 18 | | { |
| | | 19 | | try |
| | | 20 | | { |
| | | 21 | | // A minimal round-trip to the database — succeeds only if the connection is usable. |
| | 4 | 22 | | await roleReader.Query().AnyAsync(); |
| | | 23 | | |
| | 3 | 24 | | return true; |
| | | 25 | | } |
| | 1 | 26 | | catch |
| | | 27 | | { |
| | 1 | 28 | | return false; |
| | | 29 | | } |
| | 4 | 30 | | } |
| | | 31 | | } |