@sera4/essentia 1.0.11 → 1.0.13

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
@@ -2,6 +2,7 @@
2
2
 
3
3
  const pathHelper = require("path");
4
4
  const logger = require("../logger/s4-logger");
5
+ const lc = require("../last_commit");
5
6
 
6
7
  class HealthCheckError extends Error {
7
8
  constructor(m) {
@@ -21,13 +22,23 @@ class HealthCheckError extends Error {
21
22
  */
22
23
 
23
24
  class HealthCheck {
24
- constructor() {
25
+ constructor(appendData = {}) {
25
26
  this.defaultResponse = {
27
+ ...
28
+ appendData,
26
29
  status: 200,
27
30
  errors: {}
28
31
  };
29
32
 
30
33
  this.defaultPathRoute = `health_check\(.*\)?`
34
+ this.lastCallID = null;
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
+ }
31
42
 
32
43
  this.healthChecks = [];
33
44
  }
@@ -69,6 +80,9 @@ class HealthCheck {
69
80
  }));
70
81
 
71
82
  //let result = (result.reduce((e) => e.success, 200))
83
+ let callId = (Math.random()*0xFFFFFF<<0).toString(16);
84
+ this.lastCallId = callId;
85
+
72
86
  let status = this.defaultResponse.status;
73
87
 
74
88
  result.some(e => {
@@ -78,15 +92,22 @@ class HealthCheck {
78
92
  }
79
93
  })
80
94
 
95
+ // set this in the header no matter what
96
+ res.setHeader('check', callId)
97
+ res.setHeader('lastCommit', this.lastCommit)
98
+
81
99
  if (checkFormat === ".json") {
100
+ const payload = { "check": callId, "commit": this.lastCommit }
101
+
82
102
  if (status === 200) {
83
103
  res.status(status).json({
104
+ ... payload,
84
105
  "healthy":true,
85
-
86
106
  "message":"success"
87
107
  });
88
108
  } else {
89
109
  res.status(status).json({
110
+ ... payload,
90
111
  "healthy": false,
91
112
  "message": "fail",
92
113
  "services": [result]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
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