health.dart 1.23 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'enum_util.dart';
6 7 8 9
import 'message.dart';

/// Requests an application health check.
class GetHealth implements Command {
10
  @override
11 12
  final String kind = 'get_health';

13
  static GetHealth deserialize(Map<String, String> json) => new GetHealth();
14

15
  @override
pq's avatar
pq committed
16
  Map<String, String> serialize() => const <String, String>{};
17 18 19 20 21 22 23 24 25 26 27
}

/// Application health status.
enum HealthStatus {
  /// Application is known to be in a good shape and should be able to respond.
  ok,

  /// Application is not known to be in a good shape and may be unresponsive.
  bad,
}

28 29 30
final EnumIndex<HealthStatus> _healthStatusIndex =
    new EnumIndex<HealthStatus>(HealthStatus.values);

31 32 33 34 35 36 37
/// Application health status.
class Health extends Result {
  Health(this.status) {
    assert(status != null);
  }

  static Health fromJson(Map<String, dynamic> json) {
38
    return new Health(_healthStatusIndex.lookupBySimpleName(json['status']));
39 40 41 42 43
  }

  /// Health status
  final HealthStatus status;

44
  @override
pq's avatar
pq committed
45
  Map<String, dynamic> toJson() => <String, dynamic>{
46
    'status': _healthStatusIndex.toSimpleName(status)
47 48
  };
}