run method

Future run()
override

Implementation

Future<dynamic> run() async
{
  Map<String, StatusActionTest> checks = {};
  for (var key in allChecks.keys) {
    try {
      checks.addAll(await allChecks[key]!.check(this));
    } catch (e) {
      checks[key] = StatusActionTest(false);
    }
  }
  if (_uptimeTimer == null) {
    _uptimeTimer = DateTime.now();
  }
  var healthy = checks.values.map((a)=>a.isOk).reduce((a, b) => a && b);
  if (!healthy) {
    this.responseStatus = HttpStatus.serviceUnavailable;
  }
  var now = DateTime.now();
  Map checksInfo = {};
  checks.forEach((key, value) {
    checksInfo[key] = {
      'ok': value.isOk,
      'value': value.value
    };
  });

  return {
    'time': now.toString(),
    'uptime': now.difference(_uptimeTimer!).inSeconds.toDouble() / (60 * 60 * 24),
    'healthy': healthy,
    'checks': checksInfo
  };
}