Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
48
lib/Peach/see/health/ViewHealth.dart
Normal file
48
lib/Peach/see/health/ViewHealth.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user