Spaces:
Sleeping
Sleeping
Backup Agent commited on
Commit ·
011017e
1
Parent(s): 271338b
Refactor loadAndConnectServers to load all sub-servers in parallel to avoid timeout blocks
Browse files
index.js
CHANGED
|
@@ -64,8 +64,8 @@ async function loadAndConnectServers() {
|
|
| 64 |
}
|
| 65 |
activeClients.clear();
|
| 66 |
|
| 67 |
-
// Connect to
|
| 68 |
-
|
| 69 |
try {
|
| 70 |
console.log(`[Registry] Connecting to sub-server: ${name}...`);
|
| 71 |
let transport;
|
|
@@ -78,7 +78,7 @@ async function loadAndConnectServers() {
|
|
| 78 |
env: { ...process.env, ...serverConfig.data.env }
|
| 79 |
});
|
| 80 |
} else {
|
| 81 |
-
|
| 82 |
}
|
| 83 |
|
| 84 |
const client = new Client(
|
|
@@ -95,7 +95,10 @@ async function loadAndConnectServers() {
|
|
| 95 |
} catch (e) {
|
| 96 |
console.error(`[Registry Error] Failed to connect to '${name}':`, e.message);
|
| 97 |
}
|
| 98 |
-
}
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
// ---------------------------------------------------------------------------
|
|
|
|
| 64 |
}
|
| 65 |
activeClients.clear();
|
| 66 |
|
| 67 |
+
// Connect to registered servers in parallel
|
| 68 |
+
const connectionPromises = Object.entries(registry).map(async ([name, serverConfig]) => {
|
| 69 |
try {
|
| 70 |
console.log(`[Registry] Connecting to sub-server: ${name}...`);
|
| 71 |
let transport;
|
|
|
|
| 78 |
env: { ...process.env, ...serverConfig.data.env }
|
| 79 |
});
|
| 80 |
} else {
|
| 81 |
+
return;
|
| 82 |
}
|
| 83 |
|
| 84 |
const client = new Client(
|
|
|
|
| 95 |
} catch (e) {
|
| 96 |
console.error(`[Registry Error] Failed to connect to '${name}':`, e.message);
|
| 97 |
}
|
| 98 |
+
});
|
| 99 |
+
|
| 100 |
+
await Promise.allSettled(connectionPromises);
|
| 101 |
+
console.log(`[Registry] Parallel load complete. Active servers: ${activeClients.size}`);
|
| 102 |
}
|
| 103 |
|
| 104 |
// ---------------------------------------------------------------------------
|