channel-worker 2.1.0 → 2.1.2
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 +25 -11
- package/package.json +1 -1
package/lib/api-client.js
CHANGED
|
@@ -86,6 +86,10 @@ class ApiClient {
|
|
|
86
86
|
return this.request('POST', '/workers/scene-dispatch', { nst_profile_id: nstProfileId });
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
async rendererHasCommands(nstProfileId) {
|
|
90
|
+
return this.request('GET', `/workers/renderer-has-commands?nst_profile_id=${encodeURIComponent(nstProfileId)}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
89
93
|
// Extension download
|
|
90
94
|
async getExtensionVersion() {
|
|
91
95
|
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,7 +1158,29 @@ 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
|
|
1162
|
+
for (const r of offlineRenderers) {
|
|
1163
|
+
try {
|
|
1164
|
+
const cmdCount = await this.api.rendererHasCommands(r.nst_profile_id);
|
|
1165
|
+
if (cmdCount > 0) {
|
|
1166
|
+
console.log(`[scene-dispatch] Crash recovery: ${r.name} has ${cmdCount} commands but not running — relaunching`);
|
|
1167
|
+
try {
|
|
1168
|
+
await this._launchRendererProfile(r);
|
|
1169
|
+
runningRenderers.push(r);
|
|
1170
|
+
console.log(`[scene-dispatch] ${r.name} recovered`);
|
|
1171
|
+
} catch (err) {
|
|
1172
|
+
console.error(`[scene-dispatch] Failed to recover ${r.name}: ${err.message}`);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
} catch {}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// 4. Check queued commands
|
|
1179
|
+
const queueCount = await this.api.getSceneQueueCount();
|
|
1180
|
+
if (!queueCount) { this._dispatching = false; return; }
|
|
1181
|
+
|
|
1182
|
+
// 5. Launch new profiles up to parallel limit
|
|
1183
|
+
const parallelLimit = parseInt(await this.api.getSetting('veo3_parallel_limit')) || 1;
|
|
1170
1184
|
console.log(`[scene-dispatch] running=${runningRenderers.length}/${parallelLimit} offline=${offlineRenderers.length} queue=${queueCount} names=[${runningRenderers.map(r=>r.name)}]`);
|
|
1171
1185
|
|
|
1172
1186
|
const neededLaunches = Math.min(parallelLimit - runningRenderers.length, offlineRenderers.length, queueCount);
|