geonix 1.20.0 → 1.20.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/index.d.ts +15 -9
- package/package.json +1 -1
- package/src/Connection.js +4 -4
- package/src/Gateway.js +15 -13
package/index.d.ts
CHANGED
|
@@ -77,21 +77,27 @@ declare class Registry {
|
|
|
77
77
|
export {};
|
|
78
78
|
export function Remote(service: string, ...context: (string | Stream | Object)[]): string | Stream | Object;
|
|
79
79
|
/**
|
|
80
|
+
* Send a request to a service
|
|
80
81
|
*
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {
|
|
83
|
-
* @param {
|
|
82
|
+
* @param {string} service
|
|
83
|
+
* @param {string} method
|
|
84
|
+
* @param {any[]} args
|
|
85
|
+
* @param {any[]} context
|
|
86
|
+
* @param {object} options
|
|
84
87
|
* @returns
|
|
85
88
|
*/
|
|
86
|
-
export function Request(service:
|
|
89
|
+
export function Request(service: string, method: string, args: any[], context: any[], options: object): Promise<any>;
|
|
87
90
|
/**
|
|
91
|
+
* Send a request to a service
|
|
88
92
|
*
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {
|
|
93
|
+
* @param {string} identifier
|
|
94
|
+
* @param {string} method
|
|
95
|
+
* @param {any[]} args
|
|
96
|
+
* @param {any[]} context
|
|
97
|
+
* @param {object} options
|
|
92
98
|
* @returns
|
|
93
99
|
*/
|
|
94
|
-
export function directRequest(identifier:
|
|
100
|
+
export function directRequest(identifier: string, method: string, args: any[], context: any[], options: object, service: any): Promise<any>;
|
|
95
101
|
/**
|
|
96
102
|
* Publish payload to a subject
|
|
97
103
|
*
|
|
@@ -115,7 +121,6 @@ export function RequestOptions(options: any): RequestOptionsClass;
|
|
|
115
121
|
export class Service {
|
|
116
122
|
static serviceClasses: any[];
|
|
117
123
|
static start(options?: {}): void;
|
|
118
|
-
static static(): void;
|
|
119
124
|
connections: Map<any, any>;
|
|
120
125
|
$createConnection(streamId: any): Promise<boolean>;
|
|
121
126
|
$getEnv(): {
|
|
@@ -152,6 +157,7 @@ export const stats: {};
|
|
|
152
157
|
* @returns
|
|
153
158
|
*/
|
|
154
159
|
export function parseURL(url: string): any;
|
|
160
|
+
export function getFirstItemFromAsyncIterable(asyncIterable: any): Promise<any>;
|
|
155
161
|
export function sleep(delay: number): Promise<any>;
|
|
156
162
|
export function picoid(size?: number): any;
|
|
157
163
|
export function hash(data: string | Buffer): any;
|
package/package.json
CHANGED
package/src/Connection.js
CHANGED
|
@@ -72,7 +72,9 @@ class Connection {
|
|
|
72
72
|
* Wait for the connection to be safely closed
|
|
73
73
|
*/
|
|
74
74
|
async waitUntilClosed() {
|
|
75
|
-
|
|
75
|
+
// wait for all connections to be closed
|
|
76
|
+
await Promise.all(this.#connections.map(connection => connection.closed()));
|
|
77
|
+
|
|
76
78
|
this.#closed = true;
|
|
77
79
|
console.log("gx.connection.closed");
|
|
78
80
|
|
|
@@ -181,9 +183,7 @@ class Connection {
|
|
|
181
183
|
async drain() {
|
|
182
184
|
this.#draining = true;
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
await connection.drain();
|
|
186
|
-
}
|
|
186
|
+
await Promise.all(this.#connections.map(connection => connection.drain()));
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
}
|
package/src/Gateway.js
CHANGED
|
@@ -163,20 +163,22 @@ export class Gateway {
|
|
|
163
163
|
|
|
164
164
|
// figure out if endpoints is reachable via direct http call
|
|
165
165
|
let backend;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
166
|
+
if (entry.a) {
|
|
167
|
+
for (let address of entry.a)
|
|
168
|
+
try {
|
|
169
|
+
const ac = new AbortController();
|
|
170
|
+
const timeout = setTimeout(() => ac.abort(), 500);
|
|
171
|
+
const result = await (await fetch(`http://${address}${HEALTH_CHECK_ENDPOINT}`, { signal: ac.signal })).json();
|
|
172
|
+
clearTimeout(timeout);
|
|
173
|
+
if (result.status === "healthy" && result.services?.includes(entry.n)) {
|
|
174
|
+
backend = address;
|
|
175
|
+
console.log(`${entry.n}@${entry.v} (#${entry.i}) directly reachable @ ${address}`);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
} catch {
|
|
179
|
+
// silently ignore errors
|
|
176
180
|
}
|
|
177
|
-
|
|
178
|
-
// silently ignore errors
|
|
179
|
-
}
|
|
181
|
+
}
|
|
180
182
|
|
|
181
183
|
let proxy;
|
|
182
184
|
if (!backend) {
|