channel-worker 2.3.4 → 2.3.5
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/lib/command-poller.js +27 -0
- package/package.json +1 -1
package/lib/command-poller.js
CHANGED
|
@@ -1227,6 +1227,33 @@ class CommandPoller {
|
|
|
1227
1227
|
const stillOffline = renderers.filter(r => !runningRenderers.includes(r));
|
|
1228
1228
|
console.log(`[scene-dispatch] running=${runningRenderers.length}/${parallelLimit} (flowkit=${flowkitQ} dom=${domQ}) offline=${stillOffline.length} queue=${queueCount} names=[${runningRenderers.map(r=>r.name)}]`);
|
|
1229
1229
|
|
|
1230
|
+
// 5b. Close excess profiles — when parallelLimit drops (e.g., after a DOM→FlowKit
|
|
1231
|
+
// switch), idle profiles over the cap should shut down instead of staying open
|
|
1232
|
+
// and getting throttled at /flowkit/claim-command.
|
|
1233
|
+
if (runningRenderers.length > parallelLimit) {
|
|
1234
|
+
const excess = runningRenderers.length - parallelLimit;
|
|
1235
|
+
const idleRenderers = [];
|
|
1236
|
+
for (const r of runningRenderers) {
|
|
1237
|
+
try {
|
|
1238
|
+
const c = await this.api.rendererHasCommands(r.nst_profile_id);
|
|
1239
|
+
if (c === 0) idleRenderers.push(r);
|
|
1240
|
+
} catch {}
|
|
1241
|
+
}
|
|
1242
|
+
const toClose = idleRenderers.slice(0, excess);
|
|
1243
|
+
for (const r of toClose) {
|
|
1244
|
+
console.log(`[scene-dispatch] Closing excess profile ${r.name} (over cap ${parallelLimit})`);
|
|
1245
|
+
try {
|
|
1246
|
+
await this.nst.stopProfile(r.nst_profile_id);
|
|
1247
|
+
delete this._profileLastActivity[r.nst_profile_id];
|
|
1248
|
+
if (r.name) delete this._profileLastActivity[r.name.toLowerCase()];
|
|
1249
|
+
const idx = runningRenderers.indexOf(r);
|
|
1250
|
+
if (idx >= 0) runningRenderers.splice(idx, 1);
|
|
1251
|
+
} catch (e) {
|
|
1252
|
+
console.warn(`[scene-dispatch] Failed to close excess ${r.name}: ${e.message}`);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1230
1257
|
// Count how many running profiles are actually free (no commands)
|
|
1231
1258
|
let freeRunning = 0;
|
|
1232
1259
|
for (const r of runningRenderers) {
|