feat(copyWithProgress): report copy progress every second instead of every 1%
Build / Lint & Test (push) Successful in 21s
Build / Lint & Test (push) Successful in 21s
This commit is contained in:
1 parent
70f065a3a2
commit
5fdc5a6781
2 files changed
+12
-19
No files matched your search
@@ -5,7 +5,7 @@ const path = require('path');
|
|||||||
|
|
||||||
const MAX_RETRIES = 2;
|
const MAX_RETRIES = 2;
|
||||||
const RETRY_DELAY_MS = 1000;
|
const RETRY_DELAY_MS = 1000;
|
||||||
const LOG_INTERVAL_MS = 3000;
|
const PROGRESS_INTERVAL_MS = 1000;
|
||||||
|
|
||||||
const sleep = (milliseconds) => new Promise((resolve) => {
|
const sleep = (milliseconds) => new Promise((resolve) => {
|
||||||
setTimeout(resolve, milliseconds);
|
setTimeout(resolve, milliseconds);
|
||||||
@@ -85,9 +85,7 @@ const copyWithProgress = async ({
|
|||||||
|
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
let copiedBytes = 0;
|
let copiedBytes = 0;
|
||||||
let lastReportedPercent = -1;
|
let lastProgressTime = 0;
|
||||||
let lastLoggedPercent = -10;
|
|
||||||
let lastLoggedTime = startedAt;
|
|
||||||
let intervalBytes = 0;
|
let intervalBytes = 0;
|
||||||
let intervalTime = startedAt;
|
let intervalTime = startedAt;
|
||||||
|
|
||||||
@@ -114,15 +112,15 @@ const copyWithProgress = async ({
|
|||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const percent = Math.min(Math.floor((copiedBytes / sourceSize) * 100), 99);
|
const percent = Math.min(Math.floor((copiedBytes / sourceSize) * 100), 99);
|
||||||
|
|
||||||
// Calculate ETA and speed
|
// Update UI and jobLog every second (PROGRESS_INTERVAL_MS) or on initial data chunk
|
||||||
const totalElapsedSec = Math.max((now - startedAt) / 1000, 0.001);
|
const timeSinceLastProgress = now - lastProgressTime;
|
||||||
const avgSpeedBps = copiedBytes / totalElapsedSec;
|
if (lastProgressTime === 0 || timeSinceLastProgress >= PROGRESS_INTERVAL_MS) {
|
||||||
const remainingBytes = Math.max(0, sourceSize - copiedBytes);
|
const totalElapsedSec = Math.max((now - startedAt) / 1000, 0.001);
|
||||||
const remainingSec = avgSpeedBps > 0 ? remainingBytes / avgSpeedBps : 0;
|
const avgSpeedBps = copiedBytes / totalElapsedSec;
|
||||||
const eta = formatEta(remainingSec);
|
const remainingBytes = Math.max(0, sourceSize - copiedBytes);
|
||||||
|
const remainingSec = avgSpeedBps > 0 ? remainingBytes / avgSpeedBps : 0;
|
||||||
|
const eta = formatEta(remainingSec);
|
||||||
|
|
||||||
// Update Tdarr UI on every percentage increase
|
|
||||||
if (percent > lastReportedPercent) {
|
|
||||||
if (typeof updateWorker === 'function') {
|
if (typeof updateWorker === 'function') {
|
||||||
updateWorker({
|
updateWorker({
|
||||||
percentage: percent,
|
percentage: percent,
|
||||||
@@ -132,12 +130,7 @@ const copyWithProgress = async ({
|
|||||||
if (typeof updateProgress === 'function') {
|
if (typeof updateProgress === 'function') {
|
||||||
updateProgress({ progress: percent });
|
updateProgress({ progress: percent });
|
||||||
}
|
}
|
||||||
lastReportedPercent = percent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Throttle jobLog output: every 10% or every LOG_INTERVAL_MS
|
|
||||||
const timeSinceLastLog = now - lastLoggedTime;
|
|
||||||
if (percent >= lastLoggedPercent + 10 || (timeSinceLastLog >= LOG_INTERVAL_MS && percent !== lastLoggedPercent)) {
|
|
||||||
const intSec = Math.max((now - intervalTime) / 1000, 0.001);
|
const intSec = Math.max((now - intervalTime) / 1000, 0.001);
|
||||||
const currentSpeedMb = (intervalBytes / 1024 / 1024 / intSec).toFixed(1);
|
const currentSpeedMb = (intervalBytes / 1024 / 1024 / intSec).toFixed(1);
|
||||||
const copiedMb = (copiedBytes / 1024 / 1024).toFixed(1);
|
const copiedMb = (copiedBytes / 1024 / 1024).toFixed(1);
|
||||||
@@ -150,8 +143,7 @@ const copyWithProgress = async ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastLoggedPercent = percent;
|
lastProgressTime = now;
|
||||||
lastLoggedTime = now;
|
|
||||||
intervalBytes = 0;
|
intervalBytes = 0;
|
||||||
intervalTime = now;
|
intervalTime = now;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ const AUDIO_INPUTS = {
|
|||||||
ok(copyHelperCode.includes('fs.unlinkSync(destination)'), 'copy helper removes partial copies before retrying');
|
ok(copyHelperCode.includes('fs.unlinkSync(destination)'), 'copy helper removes partial copies before retrying');
|
||||||
ok(copyHelperCode.includes('formatEta'), 'copy helper formats ETA');
|
ok(copyHelperCode.includes('formatEta'), 'copy helper formats ETA');
|
||||||
ok(copyHelperCode.includes('updateWorker'), 'copy helper updates Tdarr worker progress');
|
ok(copyHelperCode.includes('updateWorker'), 'copy helper updates Tdarr worker progress');
|
||||||
|
ok(copyHelperCode.includes('PROGRESS_INTERVAL_MS = 1000'), 'copy helper reports progress every 1 second (1000ms)');
|
||||||
|
|
||||||
// ── Subtitle default naming checks ─────────────────────────────────────────
|
// ── Subtitle default naming checks ─────────────────────────────────────────
|
||||||
console.log('\n── Subtitle default naming rules ────────────────────');
|
console.log('\n── Subtitle default naming rules ────────────────────');
|
||||||
|
|||||||
Reference in new issue
Block a user