-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
health-indicator.ts
51 lines (49 loc) · 1.28 KB
/
health-indicator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { HealthIndicatorResult } from './';
/**
* A health indicator function for a health check
*
* @publicApi
*/
export type HealthIndicatorFunction = () =>
| PromiseLike<HealthIndicatorResult>
| HealthIndicatorResult;
/**
* Represents an abstract health indicator
* with common functionalities
*
* A custom HealthIndicator should inherit the `HealthIndicator` class.
*
* ```typescript
*
* class MyHealthIndicator extends HealthIndicator {
* public check(key: string) {
* // Replace with the actual check
* const isHealthy = true;
* // Returns { [key]: { status: 'up', message: 'Up and running' } }
* return super.getStatus(key, isHealthy, { message: 'Up and running' });
* }
* }
* ```
*
* @publicApi
*/
export abstract class HealthIndicator {
/**
* Generates the health indicator result object
* @param key The key which will be used as key for the result object
* @param isHealthy Whether the health indicator is healthy
* @param data Additional data which will get appended to the result object
*/
protected getStatus(
key: string,
isHealthy: boolean,
data?: { [key: string]: any },
): HealthIndicatorResult {
return {
[key]: {
status: isHealthy ? 'up' : 'down',
...data,
},
};
}
}