better render queue multi

This commit is contained in:
sorlinv
2026-03-04 09:52:17 +01:00
parent 7670707d0d
commit b1c66f055a
4 changed files with 268 additions and 18 deletions

View File

@@ -1,13 +1,13 @@
const BlenderProcess = require("./BlenderProcess.js");
const path = require("path");
const fs = require("fs");
const os = require("os");
const { Notification } = require("electron");
const STR_STATUS_IDLE = "idle";
const STR_STATUS_RUNNING = "running";
const STR_STATUS_PAUSED = "paused";
const STR_PLACEHOLDER_CONTENT = "RENDERING";
const NB_PLACEHOLDER_MAX_SIZE = 64;
const NB_PLACEHOLDER_MAX_SIZE = 512;
class QueueManager {
constructor(obj_window) {
@@ -19,6 +19,10 @@ class QueueManager {
this.nb_last_render_ms = 0;
this.str_last_image_path = null;
this.obj_notification_config = { is_notify_each_image: false, is_notify_all_done: true };
this.str_hostname = os.hostname();
this.nb_total_render_ms = 0;
this.nb_completed_renders = 0;
this.map_remote_avgs = {};
}
set_notification_config(obj_config) {
@@ -38,6 +42,9 @@ class QueueManager {
this.str_status = STR_STATUS_RUNNING;
this.nb_last_render_ms = 0;
this.str_last_image_path = null;
this.nb_total_render_ms = 0;
this.nb_completed_renders = 0;
this.map_remote_avgs = {};
this.str_overwrite_mode = obj_config.str_overwrite_mode || "overwrite";
this.list_collections = obj_config.list_collections || [];
this.obj_render_settings = obj_config.obj_render_settings || null;
@@ -194,6 +201,8 @@ class QueueManager {
return;
}
this._check_remote_completions();
// Batch skip : boucle iterative pour eviter un stack overflow recursif
let nb_skip_count = 0;
while (this.nb_current_index < this.list_queue.length && this.str_overwrite_mode === "skip") {
@@ -215,7 +224,18 @@ class QueueManager {
if (nb_size === 0) {
break;
}
obj_check.str_status = "skipped";
if (nb_size > NB_PLACEHOLDER_MAX_SIZE) {
obj_check.str_status = "skipped";
try {
obj_check.str_done_date = fs.statSync(obj_check.str_expected_file).mtime.toISOString();
} catch (obj_date_err) {
// ignore
}
} else {
obj_check.str_status = "rendering_remote";
this._read_placeholder(obj_check);
}
this.nb_current_index++;
nb_skip_count++;
}
@@ -242,13 +262,26 @@ class QueueManager {
try {
if (fs.existsSync(obj_item.str_expected_file)) {
let nb_recheck_size = fs.statSync(obj_item.str_expected_file).size;
if (nb_recheck_size > 0) {
if (nb_recheck_size > NB_PLACEHOLDER_MAX_SIZE) {
obj_item.str_status = "skipped";
try {
obj_item.str_done_date = fs.statSync(obj_item.str_expected_file).mtime.toISOString();
} catch (obj_d_err) {
// ignore
}
this._send_log("Skip : " + obj_item.str_camera_name + " F" + obj_item.nb_frame + " (existant)");
this.nb_current_index++;
this._send_progress();
this._process_next();
return;
} else if (nb_recheck_size > 0) {
obj_item.str_status = "rendering_remote";
this._read_placeholder(obj_item);
this._send_log("Skip : " + obj_item.str_camera_name + " F" + obj_item.nb_frame + " (en cours par " + (obj_item.str_remote_hostname || "?") + ")");
this.nb_current_index++;
this._send_progress();
this._process_next();
return;
}
}
} catch (obj_recheck_err) {
@@ -264,7 +297,7 @@ class QueueManager {
if (!fs.existsSync(str_dir)) {
fs.mkdirSync(str_dir, { recursive: true });
}
fs.writeFileSync(obj_item.str_expected_file, STR_PLACEHOLDER_CONTENT);
fs.writeFileSync(obj_item.str_expected_file, this._get_placeholder_content());
} catch (obj_file_err) {
this._send_log("ERREUR creation placeholder : " + obj_file_err.message);
}
@@ -301,6 +334,9 @@ class QueueManager {
obj_item.str_status = "done";
this.nb_last_render_ms = Date.now() - nb_start;
this.nb_total_render_ms += this.nb_last_render_ms;
this.nb_completed_renders++;
obj_item.str_done_date = new Date().toISOString();
let str_image = obj_result.str_rendered_file || obj_item.str_expected_file;
this.str_last_image_path = str_image;
@@ -356,14 +392,54 @@ class QueueManager {
let list_skipped = [];
let list_stopped = [];
let list_skipped_paths = [];
let list_rendering_remote = [];
let list_item_results = [];
let nb_avg = this.nb_completed_renders > 0
? Math.round(this.nb_total_render_ms / this.nb_completed_renders)
: 0;
for (let nb_i = 0; nb_i < this.list_queue.length; nb_i++) {
if (this.list_queue[nb_i].str_status === "skipped") {
let obj_q = this.list_queue[nb_i];
if (obj_q.str_status === "skipped") {
list_skipped.push(nb_i);
list_skipped_paths.push({ nb_index: nb_i, str_path: this.list_queue[nb_i].str_expected_file });
} else if (this.list_queue[nb_i].str_status === "stopped") {
list_skipped_paths.push({ nb_index: nb_i, str_path: obj_q.str_expected_file });
list_item_results.push({
nb_index: nb_i,
str_type: "done",
str_date: obj_q.str_done_date || null,
str_resolution: obj_q.nb_resolution_x + "x" + obj_q.nb_resolution_y,
});
} else if (obj_q.str_status === "stopped") {
list_stopped.push(nb_i);
} else if (obj_q.str_status === "rendering_remote") {
list_rendering_remote.push(nb_i);
list_item_results.push({
nb_index: nb_i,
str_type: "rendering_remote",
str_remote_hostname: obj_q.str_remote_hostname || "?",
nb_remote_avg_ms: obj_q.nb_remote_avg_ms || 0,
});
} else if (obj_q.str_status === "done") {
list_item_results.push({
nb_index: nb_i,
str_type: "done",
str_date: obj_q.str_done_date || null,
str_resolution: obj_q.nb_resolution_x + "x" + obj_q.nb_resolution_y,
});
}
}
let list_machine_avgs = [];
if (nb_avg > 0) {
list_machine_avgs.push({ str_hostname: this.str_hostname, nb_avg_ms: nb_avg });
}
for (let str_h of Object.keys(this.map_remote_avgs)) {
if (this.map_remote_avgs[str_h] > 0) {
list_machine_avgs.push({ str_hostname: str_h, nb_avg_ms: this.map_remote_avgs[str_h] });
}
}
this._send_event("render-progress", {
nb_current: this.nb_current_index,
nb_total: this.list_queue.length,
@@ -375,9 +451,57 @@ class QueueManager {
list_skipped: list_skipped,
list_stopped: list_stopped,
list_skipped_paths: list_skipped_paths,
list_rendering_remote: list_rendering_remote,
list_item_results: list_item_results,
str_hostname: this.str_hostname,
nb_avg_render_ms: nb_avg,
list_machine_avgs: list_machine_avgs,
});
}
_get_placeholder_content() {
let nb_avg = this.nb_completed_renders > 0
? Math.round(this.nb_total_render_ms / this.nb_completed_renders)
: 0;
return JSON.stringify({ str_hostname: this.str_hostname, nb_avg_ms: nb_avg });
}
_read_placeholder(obj_item) {
try {
let str_content = fs.readFileSync(obj_item.str_expected_file, "utf-8");
let obj_data = JSON.parse(str_content);
obj_item.str_remote_hostname = obj_data.str_hostname || "?";
obj_item.nb_remote_avg_ms = obj_data.nb_avg_ms || 0;
if (obj_data.str_hostname && obj_data.nb_avg_ms > 0) {
this.map_remote_avgs[obj_data.str_hostname] = obj_data.nb_avg_ms;
}
} catch (obj_parse_err) {
obj_item.str_remote_hostname = "?";
obj_item.nb_remote_avg_ms = 0;
}
}
_check_remote_completions() {
for (let obj_q of this.list_queue) {
if (obj_q.str_status !== "rendering_remote") {
continue;
}
try {
if (fs.existsSync(obj_q.str_expected_file)) {
let nb_size = fs.statSync(obj_q.str_expected_file).size;
if (nb_size > NB_PLACEHOLDER_MAX_SIZE) {
obj_q.str_status = "skipped";
obj_q.str_done_date = fs.statSync(obj_q.str_expected_file).mtime.toISOString();
}
} else {
obj_q.str_status = "pending";
}
} catch (obj_check_err) {
// ignore
}
}
}
_send_log(str_message) {
this._send_event("log", str_message);
}