@kronos-integration/service-health 8.1.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronos-integration/service-health",
3
- "version": "8.1.0",
3
+ "version": "8.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -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
 
@@ -65,12 +66,15 @@ export class ServiceHealth extends Service {
65
66
  return {
66
67
  ...super.endpoints,
67
68
  heartbeat: {
69
+ direction: "out",
68
70
  multi: true,
71
+ receive: "heartbeat",
69
72
  didConnect: (endpoint, other) => {
73
+ //console.log("didConnect", endpoint.owner.heartbeatInterval);
70
74
  if (other.direction === "inout") {
71
75
  const interval = setInterval(
72
76
  () => endpoint.send("heartbeat"),
73
- 10 * 60 * 1000
77
+ endpoint.owner.heartbeatInterval * 1000
74
78
  );
75
79
  return () => clearInterval(interval);
76
80
  }
@@ -95,16 +99,24 @@ export class ServiceHealth extends Service {
95
99
  }
96
100
 
97
101
  static attributes = prepareAttributesDefinitions(
98
- Object.fromEntries(
99
- Object.entries(intervalEndpointDefs).map(([name, def]) => [
100
- name + "Interval",
101
- {
102
- ...duration_attribute,
103
- description: `${name} endpoint send interval (in seconds)`,
104
- default: 30
105
- }
106
- ])
107
- ),
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
+ },
108
120
  Service.attributes
109
121
  );
110
122
 
@@ -126,6 +138,15 @@ export class ServiceHealth extends Service {
126
138
  ? false
127
139
  : true;
128
140
  }
141
+
142
+ heartbeat(value) {
143
+ this.info(`heartbeat result ${value}`);
144
+ switch (value) {
145
+ case "fatal":
146
+ exit(-1);
147
+ break;
148
+ }
149
+ }
129
150
  }
130
151
 
131
152
  export default ServiceHealth;