rxnt-healthchecks-nestjs 1.0.1-alpha-1609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +37 -0
- package/scripts/build.script.js +16 -0
- package/src/healthcheck.module.ts +9 -0
- package/src/healthcheck.service.ts +53 -0
- package/src/index.js +8 -0
package/package.json
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"name": "rxnt-healthchecks-nestjs",
|
3
|
+
"version": "1.0.1-alpha-1609",
|
4
|
+
"description": "nestjs integration for rxnt-healthchecks",
|
5
|
+
"main": "src/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
7
|
+
"type": "module",
|
8
|
+
"scripts": {
|
9
|
+
"build": "node scripts/build.script.js",
|
10
|
+
"format": "prettier --write src/**/*",
|
11
|
+
"e2e": "mocha --timeout 15000",
|
12
|
+
"increment-version": "node ../scripts/increment-version.script.js",
|
13
|
+
"publish-package": "node ../scripts/publish.script.js"
|
14
|
+
},
|
15
|
+
"keywords": [
|
16
|
+
"healthcheck",
|
17
|
+
"health",
|
18
|
+
"nestjs"
|
19
|
+
],
|
20
|
+
"author": "RXNT",
|
21
|
+
"license": "Private",
|
22
|
+
"repository": {
|
23
|
+
"type": "git",
|
24
|
+
"url": "https://github.com/RXNT/common.git",
|
25
|
+
"directory": "rxnt-healthchecks-package"
|
26
|
+
},
|
27
|
+
"dependencies": {
|
28
|
+
"@nestjs/common": "^10.4.1",
|
29
|
+
"@rxnt/healthchecks": "0.0.11-alpha-1607"
|
30
|
+
},
|
31
|
+
"devDependencies": {
|
32
|
+
"chai": "^4.3.7",
|
33
|
+
"chai-http": "^4.4.0",
|
34
|
+
"dotenv": "^16.3.1",
|
35
|
+
"mocha": "^10.2.0"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
2
|
+
import {
|
3
|
+
HealthCheckConfiguration,
|
4
|
+
HealthCheckHandler,
|
5
|
+
HealthReport,
|
6
|
+
HealthStatus,
|
7
|
+
HealthcheckRegistration
|
8
|
+
} from '@rxnt/healthchecks';
|
9
|
+
|
10
|
+
@Injectable()
|
11
|
+
export class HealthCheckService {
|
12
|
+
|
13
|
+
private readonly handler: HealthCheckHandler
|
14
|
+
|
15
|
+
constructor() {
|
16
|
+
this.handler = new HealthCheckHandler();
|
17
|
+
}
|
18
|
+
|
19
|
+
public Setup(configuration: HealthCheckConfiguration): void {
|
20
|
+
this.handler.setup(configuration)
|
21
|
+
}
|
22
|
+
|
23
|
+
public Start() {
|
24
|
+
this.handler.start();
|
25
|
+
}
|
26
|
+
|
27
|
+
public Stop() {
|
28
|
+
this.handler.stop();
|
29
|
+
}
|
30
|
+
|
31
|
+
public Reset() {
|
32
|
+
this.handler.reset();
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
*
|
37
|
+
* @param {string[]} tags
|
38
|
+
* @param {string} name
|
39
|
+
* @param {async ()} handler
|
40
|
+
*/
|
41
|
+
public AddHealthCheck(tags: string[], name: string, check: HealthcheckRegistration) {
|
42
|
+
this.handler.addHealthCheck(tags, name, check);
|
43
|
+
}
|
44
|
+
|
45
|
+
public async ExecuteHealthCheckRequest(url): Promise<HealthReport> {
|
46
|
+
const result = await this.handler.executeHealthChecksForUrl(url);
|
47
|
+
if (result.status == HealthStatus.HEALTHY) {
|
48
|
+
return result
|
49
|
+
}
|
50
|
+
throw new InternalServerErrorException(result)
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|