@lark-apaas/fullstack-cli 1.1.42 → 1.1.43-alpha.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/package.json +1 -1
- package/templates/scripts/dev.js +13 -4
package/package.json
CHANGED
package/templates/scripts/dev.js
CHANGED
|
@@ -31,9 +31,11 @@ loadEnv();
|
|
|
31
31
|
|
|
32
32
|
// ── Configuration ─────────────────────────────────────────────────────────────
|
|
33
33
|
const LOG_DIR = process.env.LOG_DIR || 'logs';
|
|
34
|
-
const MAX_RESTART_COUNT =
|
|
34
|
+
const MAX_RESTART_COUNT = process.env.MAX_RESTART_COUNT != null && process.env.MAX_RESTART_COUNT !== ''
|
|
35
|
+
? parseInt(process.env.MAX_RESTART_COUNT, 10)
|
|
36
|
+
: Infinity;
|
|
35
37
|
const RESTART_DELAY = parseInt(process.env.RESTART_DELAY, 10) || 2;
|
|
36
|
-
const MAX_DELAY =
|
|
38
|
+
const MAX_DELAY = 8;
|
|
37
39
|
const SERVER_PORT = process.env.SERVER_PORT || '3000';
|
|
38
40
|
const CLIENT_DEV_PORT = process.env.CLIENT_DEV_PORT || '8080';
|
|
39
41
|
|
|
@@ -125,6 +127,7 @@ function startProcess({ name, command, args, cleanupPort }) {
|
|
|
125
127
|
entry.pid = child.pid;
|
|
126
128
|
entry.child = child;
|
|
127
129
|
|
|
130
|
+
const startTime = Date.now();
|
|
128
131
|
logEvent('INFO', name, `Process started (PGID: ${child.pid}): ${command} ${args.join(' ')}`);
|
|
129
132
|
|
|
130
133
|
// Pipe stdout and stderr through readline for timestamped logging
|
|
@@ -168,13 +171,19 @@ function startProcess({ name, command, args, cleanupPort }) {
|
|
|
168
171
|
|
|
169
172
|
if (stopping) break;
|
|
170
173
|
|
|
171
|
-
|
|
174
|
+
const runDuration = (Date.now() - startTime) / 1000;
|
|
175
|
+
if (runDuration >= 60) {
|
|
176
|
+
restartCount = 0;
|
|
177
|
+
logEvent('INFO', name, `Ran for ${Math.round(runDuration)}s, resetting restart counter`);
|
|
178
|
+
} else {
|
|
179
|
+
restartCount++;
|
|
180
|
+
}
|
|
172
181
|
if (restartCount >= MAX_RESTART_COUNT) {
|
|
173
182
|
logEvent('ERROR', name, `Max restart count (${MAX_RESTART_COUNT}) reached, giving up`);
|
|
174
183
|
break;
|
|
175
184
|
}
|
|
176
185
|
|
|
177
|
-
const delay = Math.min(RESTART_DELAY * (1 << (restartCount - 1)), MAX_DELAY);
|
|
186
|
+
const delay = Math.min(RESTART_DELAY * (1 << Math.max(0, restartCount - 1)), MAX_DELAY);
|
|
178
187
|
logEvent('WARN', name, `Process exited with code ${exitCode}, restarting (${restartCount}/${MAX_RESTART_COUNT}) in ${delay}s...`);
|
|
179
188
|
await sleep(delay * 1000);
|
|
180
189
|
}
|