@sera4/essentia 1.0.12 → 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 CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict"
2
2
 
3
3
  const pathHelper = require("path");
4
- const logger = require("../logger/s4-logger");
5
4
 
6
5
  class HealthCheckError extends Error {
7
6
  constructor(m) {
@@ -10,7 +9,7 @@ class HealthCheckError extends Error {
10
9
  }
11
10
 
12
11
  /* Health Checking router + controller for use in all of our modules
13
- * Example use: Place the following code in your routes file
12
+ * Example use: Place the following code in your routes file
14
13
  *
15
14
  * const hc = require("@sera4/essentia").healthCheck;
16
15
  * const router = require('express').Router();
@@ -21,7 +20,7 @@ class HealthCheckError extends Error {
21
20
  */
22
21
 
23
22
  class HealthCheck {
24
- constructor(appendData = {}) {
23
+ constructor(appendData = {}) {
25
24
  this.defaultResponse = {
26
25
  ...
27
26
  appendData,
@@ -29,18 +28,17 @@ class HealthCheck {
29
28
  errors: {}
30
29
  };
31
30
 
32
- this.defaultPathRoute = `health_check\(.*\)?`
33
- this.lastCallID = null;
34
-
31
+ this.defaultPathRoute = `health_check\(.*\)?`
32
+ this.lastCallId = 0; // default start point/integer
35
33
  this.healthChecks = [];
36
34
  }
37
35
 
38
- /* call this with an async function, must support wait capability
39
- *
36
+ /* call this with an async function, must support wait capability
37
+ *
40
38
  * const dbCheck = async () => {
41
39
  * return { name: "db", "result": "success", critical: false };
42
40
  * }
43
- */
41
+ */
44
42
  addCheck(fcn) {
45
43
  this.healthChecks.push(fcn);
46
44
  }
@@ -71,9 +69,12 @@ class HealthCheck {
71
69
  return await healthCallback();
72
70
  }));
73
71
 
74
- //let result = (result.reduce((e) => e.success, 200))
75
- let callId = (Math.random()*0xFFFFFF<<0).toString(16);
76
- this.lastCallId = callId;
72
+ let callId = ++this.lastCallId;
73
+
74
+ // start the counter over
75
+ if ((callId % (1 << 30)) === 0) {
76
+ callId = this.lastCallId = 1;
77
+ }
77
78
 
78
79
  let status = this.defaultResponse.status;
79
80
 
@@ -88,15 +89,17 @@ class HealthCheck {
88
89
  res.setHeader('check', callId)
89
90
 
90
91
  if (checkFormat === ".json") {
92
+ const payload = { "check": callId }
93
+
91
94
  if (status === 200) {
92
95
  res.status(status).json({
93
- "check": callId,
96
+ ... payload,
94
97
  "healthy":true,
95
98
  "message":"success"
96
99
  });
97
100
  } else {
98
101
  res.status(status).json({
99
- "check": callId,
102
+ ... payload,
100
103
  "healthy": false,
101
104
  "message": "fail",
102
105
  "services": [result]
@@ -114,7 +117,7 @@ class HealthCheck {
114
117
  }
115
118
  } catch(error) {
116
119
  res.status(500).send();
117
- }
120
+ }
118
121
  }
119
122
  }
120
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
4
4
  "description": "A library of utilities for Teleporte Web Services",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package.tar.gz CHANGED
Binary file