channel-worker 2.1.1 → 2.1.3
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/api-client.js +4 -0
- package/lib/command-poller.js +12 -13
- package/package.json +1 -1
package/lib/api-client.js
CHANGED
|
@@ -90,6 +90,10 @@ class ApiClient {
|
|
|
90
90
|
return this.request('GET', `/workers/renderer-has-commands?nst_profile_id=${encodeURIComponent(nstProfileId)}`);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
async resetRendererCommands(nstProfileId) {
|
|
94
|
+
return this.request('POST', '/workers/reset-renderer-commands', { nst_profile_id: nstProfileId });
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
// Extension download
|
|
94
98
|
async getExtensionVersion() {
|
|
95
99
|
const data = await this.request('GET', '/extension-download/version');
|
package/lib/command-poller.js
CHANGED
|
@@ -1137,27 +1137,19 @@ class CommandPoller {
|
|
|
1137
1137
|
if (this._dispatching) return;
|
|
1138
1138
|
this._dispatching = true;
|
|
1139
1139
|
try {
|
|
1140
|
-
// 1.
|
|
1141
|
-
const queueCount = await this.api.getSceneQueueCount();
|
|
1142
|
-
if (!queueCount) { this._dispatching = false; return; }
|
|
1143
|
-
|
|
1144
|
-
// 2. Init Nstbrowser if needed
|
|
1140
|
+
// 1. Init Nstbrowser if needed
|
|
1145
1141
|
if (!this.nst) {
|
|
1146
1142
|
const apiKey = await this.api.getSetting('nst_api_key');
|
|
1147
1143
|
if (apiKey) this.nst = new NstManager(apiKey);
|
|
1148
1144
|
else { this._dispatching = false; return; }
|
|
1149
1145
|
}
|
|
1150
1146
|
|
|
1151
|
-
//
|
|
1152
|
-
const parallelLimit = parseInt(await this.api.getSetting('veo3_parallel_limit')) || 1;
|
|
1147
|
+
// 2. Get renderers + running browsers
|
|
1153
1148
|
const renderers = await this.api.getRenderers();
|
|
1154
1149
|
if (!renderers?.length) { this._dispatching = false; return; }
|
|
1155
1150
|
|
|
1156
|
-
// 4. Get running browsers from Nstbrowser (source of truth)
|
|
1157
1151
|
const running = await this.nst.getRunningBrowsers();
|
|
1158
1152
|
const runningIds = new Set(running.map(b => b.profileId));
|
|
1159
|
-
|
|
1160
|
-
// 5. Match renderers to running profiles (by name or UUID)
|
|
1161
1153
|
const runningByName = {};
|
|
1162
1154
|
for (const b of running) { if (b.name) runningByName[b.name.toLowerCase()] = b.profileId; }
|
|
1163
1155
|
const runningRenderers = renderers.filter(r => {
|
|
@@ -1166,16 +1158,18 @@ class CommandPoller {
|
|
|
1166
1158
|
});
|
|
1167
1159
|
const offlineRenderers = renderers.filter(r => !runningRenderers.includes(r));
|
|
1168
1160
|
|
|
1169
|
-
//
|
|
1161
|
+
// 3. Crash recovery — re-launch offline profiles that have assigned commands
|
|
1170
1162
|
for (const r of offlineRenderers) {
|
|
1171
1163
|
try {
|
|
1172
1164
|
const cmdCount = await this.api.rendererHasCommands(r.nst_profile_id);
|
|
1173
1165
|
if (cmdCount > 0) {
|
|
1174
1166
|
console.log(`[scene-dispatch] Crash recovery: ${r.name} has ${cmdCount} commands but not running — relaunching`);
|
|
1175
1167
|
try {
|
|
1168
|
+
// Reset stuck "running" commands back to "pending" so extension can pick them up
|
|
1169
|
+
await this.api.resetRendererCommands(r.nst_profile_id);
|
|
1176
1170
|
await this._launchRendererProfile(r);
|
|
1177
1171
|
runningRenderers.push(r);
|
|
1178
|
-
console.log(`[scene-dispatch] ${r.name} recovered`);
|
|
1172
|
+
console.log(`[scene-dispatch] ${r.name} recovered (${cmdCount} commands reset)`);
|
|
1179
1173
|
} catch (err) {
|
|
1180
1174
|
console.error(`[scene-dispatch] Failed to recover ${r.name}: ${err.message}`);
|
|
1181
1175
|
}
|
|
@@ -1183,7 +1177,12 @@ class CommandPoller {
|
|
|
1183
1177
|
} catch {}
|
|
1184
1178
|
}
|
|
1185
1179
|
|
|
1186
|
-
//
|
|
1180
|
+
// 4. Check queued commands
|
|
1181
|
+
const queueCount = await this.api.getSceneQueueCount();
|
|
1182
|
+
if (!queueCount) { this._dispatching = false; return; }
|
|
1183
|
+
|
|
1184
|
+
// 5. Launch new profiles up to parallel limit
|
|
1185
|
+
const parallelLimit = parseInt(await this.api.getSetting('veo3_parallel_limit')) || 1;
|
|
1187
1186
|
console.log(`[scene-dispatch] running=${runningRenderers.length}/${parallelLimit} offline=${offlineRenderers.length} queue=${queueCount} names=[${runningRenderers.map(r=>r.name)}]`);
|
|
1188
1187
|
|
|
1189
1188
|
const neededLaunches = Math.min(parallelLimit - runningRenderers.length, offlineRenderers.length, queueCount);
|