-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
85 lines (60 loc) · 1.78 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { io } from "socket.io-client";
import { PROCESS_METADATA, URL } from "./config.js";
import { simulateResults } from "./InsightMaker/ProcessManager.js";
// Connect to the server
const socket = io(URL);
// Function to handle errors
const handleError = (error) => {
console.log("error", error);
}
// Handle socket events
socket.on("connect", () => {
console.log("SocketIO connection established");
socket.emit("register", PROCESS_METADATA);
}
);
socket.on("disconnect", () => {
console.log("SocketIO connection closed");
}
);
socket.on("execute", async (data) => {
// Check if there is data
if (!data) {
console.log("No data provided - Job " + data["jobID"] + " aborted");
return;
}
// Job ID
const jobID = data["jobID"];
console.log("Job execution started (Job ID ", jobID, ")");
// Input parameters
let inputParameters = {};
// Iterate over the input parameters and rename the keys
for (const [key, value] of Object.entries(data)) {
// Skip the jobID
if (key === "jobID") {
continue;
}
try {
const title = PROCESS_METADATA["inputs"][key]["title"];
inputParameters[title] = value;
}
catch (error) {
continue;
}
}
//console.log("simulation", data);
let results = await simulateResults(inputParameters);
const response = {
"jobID": jobID,
"processID": PROCESS_METADATA["id"],
"results": {results},
"mimetype": "application/json"
}
socket.emit("simulation_results", response);
console.log("Job execution finished (Job ID ", jobID, ")");
}
);
socket.on("registration_success", (data) => {
console.log("registration_success", data);
}
);