@syncbridge/sqb 0.4.21 → 0.4.22

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.
@@ -15,6 +15,7 @@ export declare class SqbClientComponent<TEvents extends SqbClientComponent.Event
15
15
  protected _stop(): Promise<void>;
16
16
  protected _terminate(): Promise<void>;
17
17
  getClient(): SqbClient;
18
+ protected _testConnection(abortSignal?: AbortSignal): Promise<void>;
18
19
  /**
19
20
  * Test db connection health every 5 secs
20
21
  * @protected
@@ -56,10 +56,19 @@ let SqbClientComponent = class SqbClientComponent extends ComponentBase {
56
56
  async _start(abortSignal) {
57
57
  await super._start(abortSignal);
58
58
  const testConnection = () => {
59
- if (!(this.status === ServiceStatus.started ||
59
+ if (!(this.status === ServiceStatus.starting ||
60
60
  this.status === ServiceStatus.unhealthy))
61
61
  return;
62
- this.logger?.trace(`Testing database connection`);
62
+ this._testConnection();
63
+ let aborted = false;
64
+ let waitTimer;
65
+ abortSignal.addEventListener('abort', () => {
66
+ if (aborted)
67
+ return;
68
+ aborted = true;
69
+ clearTimeout(waitTimer);
70
+ this.client.close(0);
71
+ });
63
72
  return this.client
64
73
  .test()
65
74
  .then(() => {
@@ -67,8 +76,7 @@ let SqbClientComponent = class SqbClientComponent extends ComponentBase {
67
76
  this.setStatus(ServiceStatus.started);
68
77
  })
69
78
  .catch(err => {
70
- const timer = setTimeout(testConnection, 5000).unref();
71
- abortSignal.addEventListener('abort', () => clearTimeout(timer));
79
+ waitTimer = setTimeout(testConnection, 5000).unref();
72
80
  const msg = `Database connection failed. ${err.message}`;
73
81
  this.logger?.error(msg);
74
82
  this.setStatus(ServiceStatus.unhealthy, msg);
@@ -88,24 +96,35 @@ let SqbClientComponent = class SqbClientComponent extends ComponentBase {
88
96
  throw new Error('SqbClient component is not initialized');
89
97
  return this.client;
90
98
  }
91
- /**
92
- * Test db connection health every 5 secs
93
- * @protected
94
- */
95
- _liveness() {
96
- this.client
99
+ async _testConnection(abortSignal) {
100
+ let waitTimer;
101
+ const onAbort = () => {
102
+ clearTimeout(waitTimer);
103
+ abortSignal?.removeEventListener('abort', onAbort);
104
+ this.client.close(0);
105
+ };
106
+ abortSignal?.addEventListener('abort', onAbort);
107
+ return this.client
97
108
  .test()
98
109
  .then(() => {
99
110
  this.setStatus(ServiceStatus.started);
100
111
  })
101
112
  .catch(err => {
102
- if (this.status !== ServiceStatus.unhealthy) {
103
- const msg = `Database connection failed. ${err.message}`;
104
- this.logger?.error(msg);
105
- this.setStatus(ServiceStatus.unhealthy, msg);
106
- }
113
+ const msg = `Database connection failed. ${err.message}`;
114
+ this.logger?.error(msg);
115
+ this.setStatus(ServiceStatus.unhealthy, msg);
116
+ throw err;
107
117
  })
108
118
  .finally(() => {
119
+ abortSignal?.removeEventListener('abort', onAbort);
120
+ });
121
+ }
122
+ /**
123
+ * Test db connection health every 5 secs
124
+ * @protected
125
+ */
126
+ _liveness() {
127
+ this._testConnection().finally(() => {
109
128
  this._resetLiveness();
110
129
  });
111
130
  }
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '0.4.21';
1
+ export const version = '0.4.22';
2
2
  export const noOp = () => undefined;
3
3
  export const panatesAuthor = {
4
4
  name: 'Panates Technology AS',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/sqb",
3
- "version": "0.4.21",
3
+ "version": "0.4.22",
4
4
  "description": "SyncBridge SQB database connection components",
5
5
  "author": "Panates Inc",
6
6
  "license": "UNLICENSED",
@@ -13,8 +13,8 @@
13
13
  "oracledb": "^6.10.0"
14
14
  },
15
15
  "peerDependencies": {
16
- "@syncbridge/common": "^0.6.0",
17
- "@syncbridge/builtins": "^0.4.21",
16
+ "@syncbridge/common": "^0.6.2",
17
+ "@syncbridge/builtins": "^0.4.22",
18
18
  "@sqb/builder": ">=4.19.6 <5",
19
19
  "@sqb/connect": ">=4.19.6 <5"
20
20
  },