@cadenza.io/service 1.17.4 → 1.18.0
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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +73 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -21883,6 +21883,7 @@ declare class GraphMetadataController {
|
|
|
21883
21883
|
declare class RestController {
|
|
21884
21884
|
private static _instance;
|
|
21885
21885
|
static get instance(): RestController;
|
|
21886
|
+
fetchDataWithTimeout: (url: string, requestInit: any, timeoutMs: number) => Promise<any>;
|
|
21886
21887
|
constructor();
|
|
21887
21888
|
}
|
|
21888
21889
|
|
package/dist/index.d.ts
CHANGED
|
@@ -21883,6 +21883,7 @@ declare class GraphMetadataController {
|
|
|
21883
21883
|
declare class RestController {
|
|
21884
21884
|
private static _instance;
|
|
21885
21885
|
static get instance(): RestController;
|
|
21886
|
+
fetchDataWithTimeout: (url: string, requestInit: any, timeoutMs: number) => Promise<any>;
|
|
21886
21887
|
constructor();
|
|
21887
21888
|
}
|
|
21888
21889
|
|
package/dist/index.js
CHANGED
|
@@ -961,11 +961,21 @@ var import_node_fs = __toESM(require("fs"));
|
|
|
961
961
|
var import_node_https = __toESM(require("https"));
|
|
962
962
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
963
963
|
var RestController = class _RestController {
|
|
964
|
-
static get instance() {
|
|
965
|
-
if (!this._instance) this._instance = new _RestController();
|
|
966
|
-
return this._instance;
|
|
967
|
-
}
|
|
968
964
|
constructor() {
|
|
965
|
+
this.fetchDataWithTimeout = async function(url, requestInit, timeoutMs) {
|
|
966
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
967
|
+
try {
|
|
968
|
+
const response = await (0, import_node_fetch.default)(url, { ...requestInit, signal });
|
|
969
|
+
return await response.json();
|
|
970
|
+
} catch (error) {
|
|
971
|
+
if (error?.name === "AbortError") {
|
|
972
|
+
console.error("Fetch request timed out:", error);
|
|
973
|
+
} else {
|
|
974
|
+
console.error("Fetch error:", error);
|
|
975
|
+
}
|
|
976
|
+
throw error;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
969
979
|
CadenzaService.registry.getTaskByName.doOn(
|
|
970
980
|
"meta.rest.delegation_requested",
|
|
971
981
|
"meta.socket.delegation_requested"
|
|
@@ -1262,35 +1272,47 @@ var RestController = class _RestController {
|
|
|
1262
1272
|
`Send Handshake to ${URL}`,
|
|
1263
1273
|
async (ctx2, emit2) => {
|
|
1264
1274
|
console.log("Sending handshake", ctx2);
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1275
|
+
try {
|
|
1276
|
+
const response = await this.fetchDataWithTimeout(
|
|
1277
|
+
`${URL}/handshake`,
|
|
1278
|
+
{
|
|
1279
|
+
headers: {
|
|
1280
|
+
"Content-Type": "application/json"
|
|
1281
|
+
},
|
|
1282
|
+
method: "POST",
|
|
1283
|
+
body: JSON.stringify(ctx2.handshakeData)
|
|
1284
|
+
},
|
|
1285
|
+
1e3
|
|
1286
|
+
);
|
|
1287
|
+
console.log("Handshake result", response);
|
|
1288
|
+
if (response.__status !== "success") {
|
|
1289
|
+
const error = response.__error ?? `Failed to connect to service ${serviceName} ${ctx2.serviceInstanceId}`;
|
|
1290
|
+
console.error(error);
|
|
1291
|
+
emit2(`meta.fetch.handshake_failed:${fetchId}`, response);
|
|
1292
|
+
return { ...ctx2, __error: error, errored: true };
|
|
1293
|
+
}
|
|
1294
|
+
ctx2.serviceInstanceId = response.__serviceInstanceId;
|
|
1295
|
+
console.log(
|
|
1296
|
+
`Connected to service ${serviceName} ${URL}`,
|
|
1297
|
+
response
|
|
1298
|
+
);
|
|
1299
|
+
for (const communicationType of ctx2.communicationTypes) {
|
|
1300
|
+
emit2("meta.fetch.service_communication_established", {
|
|
1301
|
+
data: {
|
|
1302
|
+
serviceInstanceId: ctx2.serviceInstanceId,
|
|
1303
|
+
serviceInstanceClientId: CadenzaService.serviceRegistry.serviceInstanceId,
|
|
1304
|
+
communicationType
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
console.error("Error in handshake", e);
|
|
1310
|
+
return { ...ctx2, __error: e, errored: true };
|
|
1290
1311
|
}
|
|
1291
1312
|
return ctx2;
|
|
1292
1313
|
},
|
|
1293
|
-
"Sends handshake request"
|
|
1314
|
+
"Sends handshake request",
|
|
1315
|
+
{ retryCount: 5, retryDelay: 1e3 }
|
|
1294
1316
|
).doOn(`meta.fetch.handshake_requested:${fetchId}`).emits("meta.fetch.handshake_complete");
|
|
1295
1317
|
const delegateTask = CadenzaService.createMetaTask(
|
|
1296
1318
|
`Delegate flow to REST server ${URL}`,
|
|
@@ -1337,14 +1359,17 @@ var RestController = class _RestController {
|
|
|
1337
1359
|
}
|
|
1338
1360
|
let response;
|
|
1339
1361
|
try {
|
|
1340
|
-
response = await
|
|
1341
|
-
|
|
1342
|
-
|
|
1362
|
+
response = await this.fetchDataWithTimeout(
|
|
1363
|
+
`${URL}/signal`,
|
|
1364
|
+
{
|
|
1365
|
+
headers: {
|
|
1366
|
+
"Content-Type": "application/json"
|
|
1367
|
+
},
|
|
1368
|
+
method: "POST",
|
|
1369
|
+
body: JSON.stringify(ctx2)
|
|
1343
1370
|
},
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
});
|
|
1347
|
-
response = await response.json();
|
|
1371
|
+
1e3
|
|
1372
|
+
);
|
|
1348
1373
|
console.log("SIGNAL TRANSMITTED", response);
|
|
1349
1374
|
if (ctx2.__routineExecId) {
|
|
1350
1375
|
emit2(`meta.fetch.transmitted:${ctx2.__routineExecId}`, response);
|
|
@@ -1369,10 +1394,13 @@ var RestController = class _RestController {
|
|
|
1369
1394
|
async (ctx2) => {
|
|
1370
1395
|
let status;
|
|
1371
1396
|
try {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1397
|
+
status = await this.fetchDataWithTimeout(
|
|
1398
|
+
`${URL}/status`,
|
|
1399
|
+
{
|
|
1400
|
+
method: "GET"
|
|
1401
|
+
},
|
|
1402
|
+
1e3
|
|
1403
|
+
);
|
|
1376
1404
|
} catch (e) {
|
|
1377
1405
|
status = {
|
|
1378
1406
|
__error: `Error: ${e}`,
|
|
@@ -1428,6 +1456,10 @@ var RestController = class _RestController {
|
|
|
1428
1456
|
)
|
|
1429
1457
|
).doOn("meta.service_registry.dependee_registered").emitsOnFail("meta.fetch.connect_failed");
|
|
1430
1458
|
}
|
|
1459
|
+
static get instance() {
|
|
1460
|
+
if (!this._instance) this._instance = new _RestController();
|
|
1461
|
+
return this._instance;
|
|
1462
|
+
}
|
|
1431
1463
|
};
|
|
1432
1464
|
|
|
1433
1465
|
// src/network/SocketController.ts
|