8
8
class ComponentType (str , Enum ):
9
9
"""Enum used to store the component types that can be used in the HealthCheckComponentStatus class."""
10
10
11
- DATASTORE = " datastore"
12
- INTERNAL = " internal"
13
- FULLNODE = " fullnode"
11
+ DATASTORE = ' datastore'
12
+ INTERNAL = ' internal'
13
+ FULLNODE = ' fullnode'
14
14
15
15
16
16
class HealthCheckStatus (str , Enum ):
17
17
"""Enum used to store the component status that can be used in the HealthCheckComponentStatus class."""
18
18
19
- PASS = " pass"
20
- WARN = " warn"
21
- FAIL = " fail"
19
+ PASS = ' pass'
20
+ WARN = ' warn'
21
+ FAIL = ' fail'
22
22
23
23
24
24
@dataclass
@@ -35,29 +35,29 @@ class ComponentHealthCheck:
35
35
observed_unit : Optional [str ] = None
36
36
37
37
def __post_init__ (self ) -> None :
38
- self .time = datetime .utcnow ().strftime (" %Y-%m-%dT%H:%M:%SZ" )
38
+ self .time = datetime .utcnow ().strftime (' %Y-%m-%dT%H:%M:%SZ' )
39
39
40
40
def to_json (self ) -> dict [str , str ]:
41
41
"""Return a dict representation of the object. All field names are converted to camel case."""
42
42
json = {
43
- " componentType" : self .component_type .value ,
44
- " status" : self .status .value ,
45
- " output" : self .output ,
43
+ ' componentType' : self .component_type .value ,
44
+ ' status' : self .status .value ,
45
+ ' output' : self .output ,
46
46
}
47
47
48
48
if self .time :
49
- json [" time" ] = self .time
49
+ json [' time' ] = self .time
50
50
51
51
if self .component_id :
52
- json [" componentId" ] = self .component_id
52
+ json [' componentId' ] = self .component_id
53
53
54
54
if self .observed_value :
55
55
assert (
56
56
self .observed_unit is not None
57
- ), " observed_unit must be set if observed_value is set"
57
+ ), ' observed_unit must be set if observed_value is set'
58
58
59
- json [" observedValue" ] = self .observed_value
60
- json [" observedUnit" ] = self .observed_unit
59
+ json [' observedValue' ] = self .observed_value
60
+ json [' observedUnit' ] = self .observed_unit
61
61
62
62
return json
63
63
@@ -71,7 +71,7 @@ class ServiceHealthCheck:
71
71
72
72
@property
73
73
def status (self ) -> HealthCheckStatus :
74
- "Return the status of the health check based on the status of the components."
74
+ """ Return the status of the health check based on the status of the components."" "
75
75
status = HealthCheckStatus .PASS
76
76
77
77
for component_checks in self .checks .values ():
@@ -87,7 +87,7 @@ def __post_init__(self) -> None:
87
87
"""Perform some validations after the object is initialized."""
88
88
# Make sure the checks dict is not empty
89
89
if not self .checks :
90
- raise ValueError (" checks dict cannot be empty" )
90
+ raise ValueError (' checks dict cannot be empty' )
91
91
92
92
def get_http_status_code (self ) -> int :
93
93
"""Return the HTTP status code for the status."""
@@ -96,14 +96,14 @@ def get_http_status_code(self) -> int:
96
96
elif self .status in [HealthCheckStatus .WARN , HealthCheckStatus .FAIL ]:
97
97
return 503
98
98
else :
99
- raise ValueError (f" Missing treatment for status { self .status } " )
99
+ raise ValueError (f' Missing treatment for status { self .status } ' )
100
100
101
101
def to_json (self ) -> dict [str , Any ]:
102
102
"""Return a dict representation of the object. All field names are converted to camel case."""
103
103
return {
104
- " status" : self .status .value ,
105
- " description" : self .description ,
106
- " checks" : {k : [c .to_json () for c in v ] for k , v in self .checks .items ()},
104
+ ' status' : self .status .value ,
105
+ ' description' : self .description ,
106
+ ' checks' : {k : [c .to_json () for c in v ] for k , v in self .checks .items ()},
107
107
}
108
108
109
109
0 commit comments