checkHealth method
Performs a health check on the local and remote adapters.
This method checks the connectivity and the individual health of both adapters, combines them into a DatumHealth object, updates the status stream, and returns the result.
Implementation
Future<DatumHealth> checkHealth() async {
final localStatus = await localAdapter.checkHealth();
final remoteStatus = await remoteAdapter.checkHealth();
final isConnected = await connectivityChecker.isConnected;
DatumSyncHealth overallStatus;
if (!isConnected) {
overallStatus = DatumSyncHealth.offline;
} else if (localStatus == AdapterHealthStatus.unhealthy || remoteStatus == AdapterHealthStatus.unhealthy) {
overallStatus = DatumSyncHealth.degraded;
} else {
overallStatus = DatumSyncHealth.healthy;
}
final health = DatumHealth(
status: overallStatus,
localAdapterStatus: localStatus,
remoteAdapterStatus: remoteStatus,
);
// Update the health status in the main status snapshot.
statusSubject.add(statusSubject.value.copyWith(health: health));
return health;
}