@kronos-integration/service-health 8.0.69 → 8.1.1
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 +1 -1
- package/src/service-health.mjs +44 -11
package/package.json
CHANGED
package/src/service-health.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import process from "process";
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { exit } from "node:process";
|
|
2
3
|
import { prepareAttributesDefinitions, duration_attribute } from "pacc";
|
|
3
4
|
import { Service } from "@kronos-integration/service";
|
|
4
5
|
|
|
@@ -64,6 +65,21 @@ export class ServiceHealth extends Service {
|
|
|
64
65
|
static get endpoints() {
|
|
65
66
|
return {
|
|
66
67
|
...super.endpoints,
|
|
68
|
+
heartbeat: {
|
|
69
|
+
direction: "out",
|
|
70
|
+
multi: true,
|
|
71
|
+
receive: "heartbeat",
|
|
72
|
+
didConnect: (endpoint, other) => {
|
|
73
|
+
//console.log("didConnect", endpoint.owner.heartbeatInterval);
|
|
74
|
+
if (other.direction === "inout") {
|
|
75
|
+
const interval = setInterval(
|
|
76
|
+
() => endpoint.send("heartbeat"),
|
|
77
|
+
endpoint.owner.heartbeatInterval * 1000
|
|
78
|
+
);
|
|
79
|
+
return () => clearInterval(interval);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
67
83
|
state: {
|
|
68
84
|
multi: true,
|
|
69
85
|
receive: "isHealthy",
|
|
@@ -83,16 +99,24 @@ export class ServiceHealth extends Service {
|
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
static attributes = prepareAttributesDefinitions(
|
|
86
|
-
|
|
87
|
-
Object.
|
|
88
|
-
name
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
{
|
|
103
|
+
...Object.fromEntries(
|
|
104
|
+
Object.entries(intervalEndpointDefs).map(([name, def]) => [
|
|
105
|
+
name + "Interval",
|
|
106
|
+
{
|
|
107
|
+
...duration_attribute,
|
|
108
|
+
name: name + "Interval",
|
|
109
|
+
description: `${name} endpoint send interval (in seconds)`,
|
|
110
|
+
default: 30
|
|
111
|
+
}
|
|
112
|
+
])
|
|
113
|
+
),
|
|
114
|
+
heartbeatInterval: {
|
|
115
|
+
...duration_attribute,
|
|
116
|
+
name: "heartbeatInterval",
|
|
117
|
+
default: 30
|
|
118
|
+
}
|
|
119
|
+
},
|
|
96
120
|
Service.attributes
|
|
97
121
|
);
|
|
98
122
|
|
|
@@ -114,6 +138,15 @@ export class ServiceHealth extends Service {
|
|
|
114
138
|
? false
|
|
115
139
|
: true;
|
|
116
140
|
}
|
|
141
|
+
|
|
142
|
+
heartbeat(value) {
|
|
143
|
+
this.info(`heartbeat result ${value}`);
|
|
144
|
+
switch (value) {
|
|
145
|
+
case "fatal":
|
|
146
|
+
exit(-1);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
117
150
|
}
|
|
118
151
|
|
|
119
152
|
export default ServiceHealth;
|