@cryptexlabs/codex-nodejs-common 0.6.3 → 0.6.4

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/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptexlabs/codex-nodejs-common",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Common code for Assistant applications",
5
5
  "main": "lib/src/index.js",
6
6
  "repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
@@ -9,6 +9,8 @@ export declare class ElasticsearchHealthzService {
9
9
  private readonly elasticsearchService;
10
10
  private readonly elasticsearchPinger;
11
11
  private readonly healthzService;
12
+ private isWaitingForHealthy;
13
+ private isStarted;
12
14
  constructor(config: DefaultConfig, logger: LoggerService, elasticsearchService: ElasticsearchService, elasticsearchPinger: ElasticsearchPinger, healthzService: HealthzService);
13
15
  start(): Promise<void>;
14
16
  waitForHealthy(): Promise<void>;
@@ -25,19 +25,31 @@ let ElasticsearchHealthzService = class ElasticsearchHealthzService {
25
25
  this.elasticsearchService = elasticsearchService;
26
26
  this.elasticsearchPinger = elasticsearchPinger;
27
27
  this.healthzService = healthzService;
28
+ this.isWaitingForHealthy = false;
29
+ this.isStarted = false;
28
30
  }
29
31
  async start() {
30
- await this.healthzService.makeUnhealthy(healthz_1.HealthzComponentEnum.DATABASE_ELASTICSEARCH);
31
- this._ping().then();
32
- setInterval(() => {
33
- this._ping();
34
- }, this.config.elasticsearch.pingIntervalSeconds * 1000);
32
+ if (!this.isStarted) {
33
+ this.isStarted = true;
34
+ await this.healthzService.makeUnhealthy(healthz_1.HealthzComponentEnum.DATABASE_ELASTICSEARCH);
35
+ this._ping().then();
36
+ setInterval(() => {
37
+ this._ping();
38
+ }, this.config.elasticsearch.pingIntervalSeconds * 1000);
39
+ }
35
40
  }
36
41
  async waitForHealthy() {
37
- this.logger.log("Waiting for elasticsearch connection", "info");
38
- await this.elasticsearchPinger.waitForReady();
39
- this.logger.log("Elasticsearch service connected", "info");
40
- await this.healthzService.makeHealthy(healthz_1.HealthzComponentEnum.DATABASE_ELASTICSEARCH);
42
+ if (!this.isWaitingForHealthy) {
43
+ this.isWaitingForHealthy = true;
44
+ this.logger.log("Waiting for elasticsearch connection", "info");
45
+ await this.elasticsearchPinger.waitForReady();
46
+ this.logger.log("Elasticsearch service connected", "info");
47
+ await this.healthzService.makeHealthy(healthz_1.HealthzComponentEnum.DATABASE_ELASTICSEARCH);
48
+ this.isWaitingForHealthy = false;
49
+ }
50
+ else {
51
+ await this.elasticsearchPinger.waitForReady();
52
+ }
41
53
  }
42
54
  async _ping() {
43
55
  const success = await this.elasticsearchService.ping();
@@ -1 +1 @@
1
- {"version":3,"file":"elasticsearch-healthz.service.js","sourceRoot":"","sources":["../../../../src/service/elasticsearch/elasticsearch-healthz.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,yCAA6C;AAC7C,yDAA6D;AAC7D,wCAAkE;AAElE,iEAA6D;AAG7D,IAAa,2BAA2B,GAAxC,MAAa,2BAA2B;IACtC,YACqC,MAAqB,EACrB,MAAqB,EAEvC,oBAA0C,EAE1C,mBAAwC,EACb,cAA8B;QANvC,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAe;QAEvC,yBAAoB,GAApB,oBAAoB,CAAsB;QAE1C,wBAAmB,GAAnB,mBAAmB,CAAqB;QACb,mBAAc,GAAd,cAAc,CAAgB;IACzE,CAAC;IAEJ,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CACrC,8BAAoB,CAAC,sBAAsB,CAC5C,CAAC;QACF,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QACpB,WAAW,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,mBAAmB,GA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AC,CAAC;YAE3D,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CACnC,8BAAoB,CAAC,sBAAsB,CAC5C,CAAC;YACF,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;SAClC;aAAM;YACL,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,CAAC;SAC/C;IACH,CAAC;IAEO,KAAK,CAAC,KAAK;QACjB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC;QACvD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CACnC,8BAAoB,CAAC,sBAAsB,CAC5C,CAAC;SACH;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,EAAE,EAAE,CAAC,CAAC;YACpE,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CACrC,8BAAoB,CAAC,sBAAsB,CAC5C,CAAC;SACH;IACH,CAAC;CACF,CAAA;AA3DY,2BAA2B;IADvC,mBAAU,EAAE;IAMR,WAAA,eAAM,CAAC,QAAQ,CAAC,CAAA;IAChB,WAAA,eAAM,CAAC,QAAQ,CAAC,CAAA;IAChB,WAAA,eAAM,CAAC,uBAAuB,CAAC,CAAA;IAE/B,WAAA,eAAM,CAAC,sBAAsB,CAAC,CAAA;IAE9B,WAAA,eAAM,CAAC,iBAAiB,CAAC,CAAA;qCANiB,sBAAa,UAGjB,oCAAoB;QAErB,0CAAmB;QACG,wBAAc;GAXjE,2BAA2B,CA2DvC;AA3DY,kEAA2B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptexlabs/codex-nodejs-common",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Common code for Assistant applications",
5
5
  "main": "lib/src/index.js",
6
6
  "repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
@@ -7,6 +7,9 @@ import { ElasticsearchPinger } from "./elasticsearch.pinger";
7
7
 
8
8
  @Injectable()
9
9
  export class ElasticsearchHealthzService {
10
+ private isWaitingForHealthy: boolean = false;
11
+
12
+ private isStarted: boolean = false;
10
13
  constructor(
11
14
  @Inject("CONFIG") private readonly config: DefaultConfig,
12
15
  @Inject("LOGGER") private readonly logger: LoggerService,
@@ -18,25 +21,34 @@ export class ElasticsearchHealthzService {
18
21
  ) {}
19
22
 
20
23
  async start() {
21
- await this.healthzService.makeUnhealthy(
22
- HealthzComponentEnum.DATABASE_ELASTICSEARCH
23
- );
24
- this._ping().then();
25
- setInterval(() => {
26
- this._ping();
27
- }, this.config.elasticsearch.pingIntervalSeconds * 1000);
24
+ if (!this.isStarted) {
25
+ this.isStarted = true;
26
+ await this.healthzService.makeUnhealthy(
27
+ HealthzComponentEnum.DATABASE_ELASTICSEARCH
28
+ );
29
+ this._ping().then();
30
+ setInterval(() => {
31
+ this._ping();
32
+ }, this.config.elasticsearch.pingIntervalSeconds * 1000);
33
+ }
28
34
  }
29
35
 
30
36
  async waitForHealthy(): Promise<void> {
31
- this.logger.log("Waiting for elasticsearch connection", "info");
37
+ if (!this.isWaitingForHealthy) {
38
+ this.isWaitingForHealthy = true;
39
+ this.logger.log("Waiting for elasticsearch connection", "info");
32
40
 
33
- await this.elasticsearchPinger.waitForReady();
41
+ await this.elasticsearchPinger.waitForReady();
34
42
 
35
- this.logger.log("Elasticsearch service connected", "info");
43
+ this.logger.log("Elasticsearch service connected", "info");
36
44
 
37
- await this.healthzService.makeHealthy(
38
- HealthzComponentEnum.DATABASE_ELASTICSEARCH
39
- );
45
+ await this.healthzService.makeHealthy(
46
+ HealthzComponentEnum.DATABASE_ELASTICSEARCH
47
+ );
48
+ this.isWaitingForHealthy = false;
49
+ } else {
50
+ await this.elasticsearchPinger.waitForReady();
51
+ }
40
52
  }
41
53
 
42
54
  private async _ping() {