@sera4/essentia 1.0.13 → 1.0.15
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/health/index.js +15 -23
- package/package.json +1 -1
- package/package.tar.gz +0 -0
package/health/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
3
|
const pathHelper = require("path");
|
|
4
|
-
const logger = require("../logger/s4-logger");
|
|
5
|
-
const lc = require("../last_commit");
|
|
6
4
|
|
|
7
5
|
class HealthCheckError extends Error {
|
|
8
6
|
constructor(m) {
|
|
@@ -11,7 +9,7 @@ class HealthCheckError extends Error {
|
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
/* Health Checking router + controller for use in all of our modules
|
|
14
|
-
* Example use: Place the following code in your routes file
|
|
12
|
+
* Example use: Place the following code in your routes file
|
|
15
13
|
*
|
|
16
14
|
* const hc = require("@sera4/essentia").healthCheck;
|
|
17
15
|
* const router = require('express').Router();
|
|
@@ -22,7 +20,7 @@ class HealthCheckError extends Error {
|
|
|
22
20
|
*/
|
|
23
21
|
|
|
24
22
|
class HealthCheck {
|
|
25
|
-
constructor(appendData = {}) {
|
|
23
|
+
constructor(appendData = {}) {
|
|
26
24
|
this.defaultResponse = {
|
|
27
25
|
...
|
|
28
26
|
appendData,
|
|
@@ -30,25 +28,17 @@ class HealthCheck {
|
|
|
30
28
|
errors: {}
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
this.defaultPathRoute = `health_check\(.*\)?`
|
|
34
|
-
this.
|
|
35
|
-
this.lastCommit = "unknown"
|
|
36
|
-
|
|
37
|
-
// dev versions don't generate this by default
|
|
38
|
-
try {
|
|
39
|
-
this.lastCommit = lc.getLastCommitSync().commit;
|
|
40
|
-
} catch(e) {
|
|
41
|
-
}
|
|
42
|
-
|
|
31
|
+
this.defaultPathRoute = `health_check\(.*\)?`
|
|
32
|
+
this.lastCallId = 0; // default start point/integer
|
|
43
33
|
this.healthChecks = [];
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
/* call this with an async function, must support wait capability
|
|
47
|
-
*
|
|
36
|
+
/* call this with an async function, must support wait capability
|
|
37
|
+
*
|
|
48
38
|
* const dbCheck = async () => {
|
|
49
39
|
* return { name: "db", "result": "success", critical: false };
|
|
50
40
|
* }
|
|
51
|
-
*/
|
|
41
|
+
*/
|
|
52
42
|
addCheck(fcn) {
|
|
53
43
|
this.healthChecks.push(fcn);
|
|
54
44
|
}
|
|
@@ -79,9 +69,12 @@ class HealthCheck {
|
|
|
79
69
|
return await healthCallback();
|
|
80
70
|
}));
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
let callId = ++this.lastCallId;
|
|
73
|
+
|
|
74
|
+
// start the counter over
|
|
75
|
+
if ((callId % (1 << 30)) === 0) {
|
|
76
|
+
callId = this.lastCallId = 1;
|
|
77
|
+
}
|
|
85
78
|
|
|
86
79
|
let status = this.defaultResponse.status;
|
|
87
80
|
|
|
@@ -94,10 +87,9 @@ class HealthCheck {
|
|
|
94
87
|
|
|
95
88
|
// set this in the header no matter what
|
|
96
89
|
res.setHeader('check', callId)
|
|
97
|
-
res.setHeader('lastCommit', this.lastCommit)
|
|
98
90
|
|
|
99
91
|
if (checkFormat === ".json") {
|
|
100
|
-
const payload = { "check": callId
|
|
92
|
+
const payload = { "check": callId }
|
|
101
93
|
|
|
102
94
|
if (status === 200) {
|
|
103
95
|
res.status(status).json({
|
|
@@ -125,7 +117,7 @@ class HealthCheck {
|
|
|
125
117
|
}
|
|
126
118
|
} catch(error) {
|
|
127
119
|
res.status(500).send();
|
|
128
|
-
}
|
|
120
|
+
}
|
|
129
121
|
}
|
|
130
122
|
}
|
|
131
123
|
|
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|