From 7494b87ba121ed12f40d323b35c7361d0b07dd43 Mon Sep 17 00:00:00 2001 From: Thomas Beckers Date: Mon, 23 Nov 2020 15:16:11 +0100 Subject: [PATCH] Updated health check --- .../Interfaces/Services/IHealthCheckService.cs | 15 +++++++++++++++ Swabbr.Core/Services/HealthCheckService.cs | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Swabbr.Core/Interfaces/Services/IHealthCheckService.cs b/Swabbr.Core/Interfaces/Services/IHealthCheckService.cs index 87ca778c..1521944f 100644 --- a/Swabbr.Core/Interfaces/Services/IHealthCheckService.cs +++ b/Swabbr.Core/Interfaces/Services/IHealthCheckService.cs @@ -10,6 +10,21 @@ public interface IHealthCheckService /// /// Checks if our backend is healthy. /// + /// + /// This can generally be used as a wrapper + /// call to call all other checks in this + /// interface. + /// Task IsHealthyAsync(); + + /// + /// Checks our data store. + /// + Task IsDataStoreHealthyAsync(); + + /// + /// Checks our notification service. + /// + Task IsNotificationServiceHealthyAsync(); } } diff --git a/Swabbr.Core/Services/HealthCheckService.cs b/Swabbr.Core/Services/HealthCheckService.cs index 1f84d6dd..bfb694b0 100644 --- a/Swabbr.Core/Services/HealthCheckService.cs +++ b/Swabbr.Core/Services/HealthCheckService.cs @@ -23,11 +23,23 @@ public HealthCheckService(INotificationService notificationService, _healthCheckRepository = healthCheckRepository ?? throw new ArgumentNullException(nameof(healthCheckRepository)); } + /// + /// Checks our database health. + /// + public Task IsDataStoreHealthyAsync() + => _healthCheckRepository.IsAliveAsync(); + /// /// Checks the notification service and database. /// public async Task IsHealthyAsync() - => !await _notificationService.IsServiceOnlineAsync().ConfigureAwait(false) || - !await _healthCheckRepository.IsAliveAsync().ConfigureAwait(false); + => await IsDataStoreHealthyAsync().ConfigureAwait(false) && + await IsNotificationServiceHealthyAsync().ConfigureAwait(false); + + /// + /// Checks our notification service health. + /// + public Task IsNotificationServiceHealthyAsync() + => _notificationService.IsServiceOnlineAsync(); } }