Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Updated health check
Browse files Browse the repository at this point in the history
  • Loading branch information
tabeckers committed Nov 23, 2020
1 parent bec811c commit 7494b87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Swabbr.Core/Interfaces/Services/IHealthCheckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ public interface IHealthCheckService
/// <summary>
/// Checks if our backend is healthy.
/// </summary>
/// <remarks>
/// This can generally be used as a wrapper
/// call to call all other checks in this
/// interface.
/// </remarks>
Task<bool> IsHealthyAsync();

/// <summary>
/// Checks our data store.
/// </summary>
Task<bool> IsDataStoreHealthyAsync();

/// <summary>
/// Checks our notification service.
/// </summary>
Task<bool> IsNotificationServiceHealthyAsync();
}
}
16 changes: 14 additions & 2 deletions Swabbr.Core/Services/HealthCheckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@ public HealthCheckService(INotificationService notificationService,
_healthCheckRepository = healthCheckRepository ?? throw new ArgumentNullException(nameof(healthCheckRepository));
}

/// <summary>
/// Checks our database health.
/// </summary>
public Task<bool> IsDataStoreHealthyAsync()
=> _healthCheckRepository.IsAliveAsync();

/// <summary>
/// Checks the notification service and database.
/// </summary>
public async Task<bool> IsHealthyAsync()
=> !await _notificationService.IsServiceOnlineAsync().ConfigureAwait(false) ||
!await _healthCheckRepository.IsAliveAsync().ConfigureAwait(false);
=> await IsDataStoreHealthyAsync().ConfigureAwait(false) &&
await IsNotificationServiceHealthyAsync().ConfigureAwait(false);

/// <summary>
/// Checks our notification service health.
/// </summary>
public Task<bool> IsNotificationServiceHealthyAsync()
=> _notificationService.IsServiceOnlineAsync();
}
}

0 comments on commit 7494b87

Please sign in to comment.