reportAsync method

Future<DVHealthReport> reportAsync()

Runs every check and summarises.

Checks run together rather than in turn: a readiness probe that takes the sum of every dependency's latency starts failing on timeouts of its own as soon as there are a few of them.

Implementation

Future<DVHealthReport> reportAsync() async {
  final Map<String, DVHealthResult> results = <String, DVHealthResult>{};

  await Future.wait(<Future<void>>[
    for (final MapEntry<String, DVHealthCheck> entry in _checks.entries)
      _run(entry.key, entry.value).then((DVHealthResult result) {
        results[entry.key] = result;
      }),
  ]);

  DVHealthStatus worst = DVHealthStatus.up;
  for (final DVHealthResult result in results.values) {
    if (result.status == DVHealthStatus.down) {
      worst = DVHealthStatus.down;
      break;
    }
    if (result.status == DVHealthStatus.degraded) {
      worst = DVHealthStatus.degraded;
    }
  }

  return DVHealthReport(
    status: worst,
    checks: results,
    uptime: uptime,
    buildId: _buildId,
  );
}