import '../../about/external/data/Health.dart'; import '../../about/internal/application/ServerProfile.dart'; import '../parent/ParentViewModel.dart'; import 'ConnectHealth.dart'; class ViewHealth extends ParentViewModel { ConnectHealth connection; ViewHealth(super.context, this.connection); bool _running = false; bool get isRunning => _running; /// Checks every service on every server, reporting each result as it lands. /// A server that can't be reached marks its own services unhealthy and the /// sweep moves on, so one dead box doesn't stall the whole dashboard. void runSweep(List servers) async { if (_running) return; _running = true; notifyListeners(); connection.onSweepStarted(); for (final server in servers) { for (final service in server.services) { try { final result = await getDataManager().checkHealth(server, service); connection.onServiceChecked(service.id, result); } catch (error) { connection.onServiceChecked( service.id, HealthResult(HealthStatus.unhealthy, _describe(error)), ); } } } getDataManager().disconnect(); _running = false; notifyListeners(); connection.onSweepFinished(); } String _describe(Object error) { final text = error.toString(); return text.length > 80 ? '${text.substring(0, 77)}…' : text; } }