feat: add job progress, retry and rotating logs

This commit is contained in:
strsv committed 2026-11-06 07:52:16 +03:00
1 parent 626650e44a
commit c441d770e2
16 files changed
+297 -72

No files matched your search

+36 -1
View File
@@ -705,6 +705,14 @@ document.addEventListener("wheel", (e) => {
let jobTimer = null;
function formatEta(seconds) {
if (seconds == null) return "";
if (seconds < 60) return `${Math.max(1, Math.round(seconds))} с`;
const minutes = Math.floor(seconds / 60);
const rest = Math.round(seconds % 60);
return `${minutes} мин${rest ? ` ${rest} с` : ""}`;
}
async function pollJob() {
try {
const st = await api("/api/job");
@@ -718,11 +726,22 @@ async function pollJob() {
cancel.hidden = !busy;
cancel.disabled = false;
}
const retry = $("#jobRetry");
if (retry) {
retry.hidden = busy || !st.name;
retry.disabled = false;
}
const el = $("#jobStatus");
if (busy) {
const label = st.name === "translate" ? "перевод" : "обновление БД";
const last = (st.output || []).slice(-1)[0] || "";
el.textContent = `${label}… ${last}`.trim();
const p = st.progress;
let extra = "";
if (p && p.total) {
extra = ` ${p.current}/${p.total} (${p.percent}%)`;
if (p.eta_seconds != null) extra += ` · ~${formatEta(p.eta_seconds)}`;
}
el.textContent = `${label}…${extra} ${last}`.trim();
await loadMeta();
clearTimeout(jobTimer);
jobTimer = setTimeout(pollJob, 1500);
@@ -775,6 +794,22 @@ $("#jobCancel").addEventListener("click", async (e) => {
e.currentTarget.disabled = false;
}
});
$("#jobRetry").addEventListener("click", async (e) => {
e.currentTarget.disabled = true;
try {
const r = await api("/api/job/retry", { method: "POST", body: "{}" });
if (r.started) {
$("#jobStatus").textContent = "запуск…";
pollJob();
} else {
toast("Нет задачи для повтора");
e.currentTarget.disabled = false;
}
} catch (err) {
toast(err.message);
e.currentTarget.disabled = false;
}
});
$("#refreshInc").addEventListener("click", () =>
startJob("/api/refresh", { mode: "incremental" }, "обновление"));
$("#refreshFull").addEventListener("click", () => {