@cadenza.io/service 1.10.5 → 1.10.6
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.js +93 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1345,9 +1345,9 @@ var SocketController = class _SocketController {
|
|
|
1345
1345
|
return;
|
|
1346
1346
|
}
|
|
1347
1347
|
console.log("SocketServer: Setting up", ctx);
|
|
1348
|
+
let server;
|
|
1348
1349
|
try {
|
|
1349
|
-
|
|
1350
|
-
ctx.__socketServer = server;
|
|
1350
|
+
server = new import_socket.Server((_a2 = ctx.__httpsServer) != null ? _a2 : ctx.__httpServer);
|
|
1351
1351
|
console.log("SocketServer:", server);
|
|
1352
1352
|
const profile = (_b2 = ctx.__securityProfile) != null ? _b2 : "medium";
|
|
1353
1353
|
server.use((socket, next) => {
|
|
@@ -1397,114 +1397,101 @@ var SocketController = class _SocketController {
|
|
|
1397
1397
|
console.log("SocketServer: Setup complete");
|
|
1398
1398
|
} catch (err) {
|
|
1399
1399
|
console.error("Socket setup error:", err);
|
|
1400
|
-
return
|
|
1400
|
+
return __spreadProps(__spreadValues({}, ctx), { __error: err, errored: true });
|
|
1401
1401
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
"
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
destroyCondition: (ctx3) => {
|
|
1438
|
-
var _a2;
|
|
1439
|
-
return ctx3.data.progress === 1 || ((_a2 = ctx3.data) == null ? void 0 : _a2.progress) === void 0;
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
).doOn(
|
|
1443
|
-
`meta.node.routine_execution_progress:${deputyExecId}`,
|
|
1444
|
-
`meta.node.graph_completed:${deputyExecId}`
|
|
1445
|
-
).emitsOnFail(
|
|
1446
|
-
`meta.socket.progress_failed:${deputyExecId}`
|
|
1447
|
-
);
|
|
1448
|
-
CadenzaService.broker.emit(
|
|
1449
|
-
"meta.socket.delegation_requested",
|
|
1450
|
-
ctx2
|
|
1451
|
-
);
|
|
1452
|
-
}
|
|
1453
|
-
);
|
|
1454
|
-
ws.on(
|
|
1455
|
-
"signal",
|
|
1456
|
-
(ctx2, callback) => {
|
|
1457
|
-
if (CadenzaService.broker.listObservedSignals().includes(ctx2.__signalName)) {
|
|
1458
|
-
callback({
|
|
1459
|
-
__status: "success",
|
|
1460
|
-
__signalName: ctx2.__signalName
|
|
1461
|
-
});
|
|
1462
|
-
CadenzaService.broker.emit(ctx2.__signalName, ctx2);
|
|
1463
|
-
} else {
|
|
1464
|
-
callback({
|
|
1465
|
-
__status: "error",
|
|
1466
|
-
__error: "No such signal",
|
|
1467
|
-
errored: true
|
|
1468
|
-
});
|
|
1402
|
+
if (!server) {
|
|
1403
|
+
console.error("Socket setup error: No server");
|
|
1404
|
+
return __spreadProps(__spreadValues({}, ctx), { __error: "No server", errored: true });
|
|
1405
|
+
}
|
|
1406
|
+
server.on("connection", (ws) => {
|
|
1407
|
+
console.log("SocketServer: New connection");
|
|
1408
|
+
ws.on("handshake", (ctx2) => {
|
|
1409
|
+
console.log("Socket HANDSHAKE", ctx2.serviceInstanceId);
|
|
1410
|
+
ws.emit("handshake", {
|
|
1411
|
+
serviceInstanceId: CadenzaService.serviceRegistry.serviceInstanceId,
|
|
1412
|
+
__status: "success"
|
|
1413
|
+
});
|
|
1414
|
+
CadenzaService.broker.emit("meta.socket.handshake", ctx2);
|
|
1415
|
+
});
|
|
1416
|
+
ws.on(
|
|
1417
|
+
"delegation",
|
|
1418
|
+
(ctx2, callback) => {
|
|
1419
|
+
const deputyExecId = ctx2.__metadata.__deputyExecId;
|
|
1420
|
+
CadenzaService.createEphemeralMetaTask(
|
|
1421
|
+
"Resolve delegation",
|
|
1422
|
+
callback,
|
|
1423
|
+
"Resolves a delegation request using the provided callback from the client (.emitWithAck())"
|
|
1424
|
+
).doOn(`meta.node.graph_completed:${deputyExecId}`).emits(`meta.socket.delegation_resolved:${deputyExecId}`);
|
|
1425
|
+
CadenzaService.createEphemeralMetaTask(
|
|
1426
|
+
"Delegation progress update",
|
|
1427
|
+
(ctx3) => {
|
|
1428
|
+
if (ctx3.__progress !== void 0)
|
|
1429
|
+
ws.emit("delegation_progress", ctx3);
|
|
1430
|
+
},
|
|
1431
|
+
"Updates delegation progress",
|
|
1432
|
+
{
|
|
1433
|
+
once: false,
|
|
1434
|
+
destroyCondition: (ctx3) => {
|
|
1435
|
+
var _a3;
|
|
1436
|
+
return ctx3.data.progress === 1 || ((_a3 = ctx3.data) == null ? void 0 : _a3.progress) === void 0;
|
|
1469
1437
|
}
|
|
1470
1438
|
}
|
|
1471
|
-
)
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
);
|
|
1486
|
-
ws.on("disconnect", () => {
|
|
1487
|
-
CadenzaService.broker.emit("meta.socket.disconnected", {
|
|
1488
|
-
__wsId: ws.id
|
|
1439
|
+
).doOn(
|
|
1440
|
+
`meta.node.routine_execution_progress:${deputyExecId}`,
|
|
1441
|
+
`meta.node.graph_completed:${deputyExecId}`
|
|
1442
|
+
).emitsOnFail(`meta.socket.progress_failed:${deputyExecId}`);
|
|
1443
|
+
CadenzaService.broker.emit("meta.socket.delegation_requested", ctx2);
|
|
1444
|
+
}
|
|
1445
|
+
);
|
|
1446
|
+
ws.on(
|
|
1447
|
+
"signal",
|
|
1448
|
+
(ctx2, callback) => {
|
|
1449
|
+
if (CadenzaService.broker.listObservedSignals().includes(ctx2.__signalName)) {
|
|
1450
|
+
callback({
|
|
1451
|
+
__status: "success",
|
|
1452
|
+
__signalName: ctx2.__signalName
|
|
1489
1453
|
});
|
|
1490
|
-
|
|
1491
|
-
|
|
1454
|
+
CadenzaService.broker.emit(ctx2.__signalName, ctx2);
|
|
1455
|
+
} else {
|
|
1456
|
+
callback({
|
|
1457
|
+
__status: "error",
|
|
1458
|
+
__error: "No such signal",
|
|
1459
|
+
errored: true
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
);
|
|
1464
|
+
ws.on(
|
|
1465
|
+
"status_check",
|
|
1466
|
+
(ctx2, callback) => {
|
|
1467
|
+
CadenzaService.createEphemeralMetaTask(
|
|
1468
|
+
"Resolve status check",
|
|
1469
|
+
callback,
|
|
1470
|
+
"Resolves a status check request"
|
|
1471
|
+
).doAfter(CadenzaService.serviceRegistry.getStatusTask);
|
|
1472
|
+
CadenzaService.broker.emit("meta.socket.status_check_requested", ctx2);
|
|
1473
|
+
}
|
|
1474
|
+
);
|
|
1475
|
+
ws.on("disconnect", () => {
|
|
1476
|
+
console.log("SocketServer: Disconnected");
|
|
1477
|
+
CadenzaService.broker.emit("meta.socket.disconnected", {
|
|
1478
|
+
__wsId: ws.id
|
|
1492
1479
|
});
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
)
|
|
1480
|
+
});
|
|
1481
|
+
CadenzaService.broker.emit("meta.socket.connected", { __wsId: ws.id });
|
|
1482
|
+
});
|
|
1483
|
+
CadenzaService.createMetaTask(
|
|
1484
|
+
"Broadcast status",
|
|
1485
|
+
(ctx2) => server.emit("status_update", ctx2),
|
|
1486
|
+
"Broadcasts the status of the server to all clients"
|
|
1487
|
+
).doOn("meta.service.updated");
|
|
1488
|
+
CadenzaService.createMetaTask(
|
|
1489
|
+
"Shutdown SocketServer",
|
|
1490
|
+
() => server.close(),
|
|
1491
|
+
"Shuts down the socket server"
|
|
1492
|
+
).doOn("meta.socket_server_shutdown_requested").emits("meta.socket.shutdown");
|
|
1493
|
+
return ctx;
|
|
1494
|
+
})
|
|
1508
1495
|
],
|
|
1509
1496
|
"Bootstraps the socket server"
|
|
1510
1497
|
).doOn("meta.rest.network_configured");
|
|
@@ -1554,6 +1541,7 @@ var SocketController = class _SocketController {
|
|
|
1554
1541
|
CadenzaService.broker.emit("meta.socket_client.status_received", status);
|
|
1555
1542
|
});
|
|
1556
1543
|
socket.on("disconnect", () => {
|
|
1544
|
+
console.log("SocketClient: Disconnected", serviceInstanceId);
|
|
1557
1545
|
CadenzaService.broker.emit("meta.socket_client.disconnected", {
|
|
1558
1546
|
serviceInstanceId
|
|
1559
1547
|
});
|