Files
PeachDeployments/lib/Peach/see/health/ViewHealth.dart
alvocool 38881d1fe1 Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 10:15:30 +03:00

49 lines
1.4 KiB
Dart

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<ServerProfile> 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;
}
}