badmfck-api-server 4.1.28 → 4.1.29

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.
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Watchdog = void 0;
4
+ const __1 = require("../..");
5
+ const BaseService_1 = require("../BaseService");
6
+ const ConfigService_1 = require("./ConfigService");
7
+ class Watchdog extends BaseService_1.BaseService {
8
+ config = new Map();
9
+ lastStatuses = new Map();
10
+ notifier = null;
11
+ constructor(notifier) {
12
+ super("Watchdog");
13
+ this.notifier = notifier || null;
14
+ }
15
+ applicationReady() {
16
+ this.setup();
17
+ ConfigService_1.S_CONFIG_UPDATED.subscribe(async () => { this.config = await ConfigService_1.REQ_DEPLOYMENT_CONFIG.request(); });
18
+ }
19
+ async setup() {
20
+ this.config = await ConfigService_1.REQ_DEPLOYMENT_CONFIG.request();
21
+ setInterval(() => {
22
+ for (let i of this.config) {
23
+ if (i[1].readiness) {
24
+ this.checkReadiness(i[1]);
25
+ }
26
+ }
27
+ }, 10000);
28
+ }
29
+ async checkReadiness(config) {
30
+ if (!config.readiness)
31
+ return;
32
+ const resp = await __1.Http.get(config.readiness);
33
+ if (resp.ok) {
34
+ this.statusPassed(config);
35
+ }
36
+ else {
37
+ this.statusFailed(config);
38
+ }
39
+ }
40
+ statusPassed(config) {
41
+ if (this.lastStatuses.get(config.name) === false) {
42
+ if (config.email && config.email.length > 0) {
43
+ for (let email of config.email) {
44
+ this.notifier?.notifyEmailStatus(email, "readiness-ok", config.name, "watchdog");
45
+ }
46
+ }
47
+ }
48
+ this.lastStatuses.set(config.name, true);
49
+ }
50
+ statusFailed(config) {
51
+ if (this.lastStatuses.get(config.name) !== false) {
52
+ if (config.email && config.email.length > 0) {
53
+ for (let email of config.email) {
54
+ this.notifier?.notifyEmailStatus(email, "readiness-error", config.name, "watchdog");
55
+ }
56
+ }
57
+ }
58
+ this.lastStatuses.set(config.name, false);
59
+ }
60
+ }
61
+ exports.Watchdog = Watchdog;
@@ -20,7 +20,7 @@ class Liveness extends BaseEndpoint_1.BaseEndpoint {
20
20
  setTimeout(() => {
21
21
  if (cb)
22
22
  cb(data);
23
- }, 1000 * 10);
23
+ }, 1000 * 4);
24
24
  return p;
25
25
  }
26
26
  }
@@ -7,7 +7,7 @@ export declare class Readiness extends BaseEndpoint {
7
7
  data: {
8
8
  liveness: boolean;
9
9
  wakeTime: number;
10
- request: Promise<number>;
10
+ request: number;
11
11
  };
12
12
  }>;
13
13
  }
@@ -13,7 +13,7 @@ class Readiness extends BaseEndpoint_1.BaseEndpoint {
13
13
  this.registerEndpoints([{ endpoint: "", handler: this.checkReadiness, ignoreInterceptor: true }]);
14
14
  }
15
15
  async checkReadiness(req) {
16
- const request = APIService_1.REQ_HTTP_REQUESTS_COUNT.request();
16
+ const request = await APIService_1.REQ_HTTP_REQUESTS_COUNT.request();
17
17
  return { data: { liveness: true, wakeTime: (+new Date()) - (+this.started), request: request } };
18
18
  }
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.1.28",
3
+ "version": "4.1.29",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",