clustr-ai 0.1.19 → 0.1.21
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/bin/clustr.js +35 -17
- package/dist/server/index.js +41 -41
- package/package.json +1 -1
package/bin/clustr.js
CHANGED
|
@@ -80,27 +80,45 @@ function start() {
|
|
|
80
80
|
|
|
81
81
|
const port = process.env.CLUSTR_PORT || '3100';
|
|
82
82
|
|
|
83
|
-
const server = spawn('node', [path.join(root, 'dist', 'server', 'index.js')], {
|
|
84
|
-
cwd: root,
|
|
85
|
-
stdio: 'inherit',
|
|
86
|
-
env: {
|
|
87
|
-
...process.env,
|
|
88
|
-
CLUSTR_PORT: port,
|
|
89
|
-
CLUSTR_SERVE_CLIENT: hasClient ? clientDir : '',
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
console.log(`\n Clustr is starting on http://localhost:${port}\n`);
|
|
94
|
-
|
|
95
83
|
if (!hasClient) {
|
|
96
84
|
console.log(' (Client not built — run "npm run build:client" for the full UI)');
|
|
97
85
|
console.log(' API is still available at /api/*\n');
|
|
98
86
|
}
|
|
99
87
|
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
let shuttingDown = false;
|
|
89
|
+
let restartDelay = 1000;
|
|
90
|
+
let currentServer = null;
|
|
91
|
+
|
|
92
|
+
function spawnServer() {
|
|
93
|
+
currentServer = spawn('node', [path.join(root, 'dist', 'server', 'index.js')], {
|
|
94
|
+
cwd: root,
|
|
95
|
+
stdio: 'inherit',
|
|
96
|
+
env: {
|
|
97
|
+
...process.env,
|
|
98
|
+
CLUSTR_PORT: port,
|
|
99
|
+
CLUSTR_SERVE_CLIENT: hasClient ? clientDir : '',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Reset restart delay after 30s of stability
|
|
104
|
+
const stabilityTimer = setTimeout(() => { restartDelay = 1000; }, 30000);
|
|
105
|
+
|
|
106
|
+
currentServer.on('exit', (code, signal) => {
|
|
107
|
+
clearTimeout(stabilityTimer);
|
|
108
|
+
if (shuttingDown) { process.exit(code ?? 0); return; }
|
|
109
|
+
if (signal === 'SIGINT' || signal === 'SIGTERM') { process.exit(0); return; }
|
|
110
|
+
console.error(`\n [clustr] Server exited unexpectedly (code: ${code ?? signal}). Restarting in ${restartDelay / 1000}s...\n`);
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
restartDelay = Math.min(restartDelay * 2, 30000);
|
|
113
|
+
spawnServer();
|
|
114
|
+
}, restartDelay);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
console.log(`\n Clustr is starting on http://localhost:${port}\n`);
|
|
119
|
+
|
|
120
|
+
spawnServer();
|
|
121
|
+
|
|
122
|
+
process.on('SIGINT', () => { shuttingDown = true; if (currentServer) currentServer.kill('SIGINT'); });
|
|
123
|
+
process.on('SIGTERM', () => { shuttingDown = true; if (currentServer) currentServer.kill('SIGTERM'); });
|
|
106
124
|
}
|