From 600c8d85662dfdd083abf9dcd8fa6f982ca9ef71 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 9 Nov 2026 14:29:12 +0300 Subject: [PATCH] fix(operations): the job panel shows the outcome when its resource is gone An owner who deleted their VM stayed on its page with "Delete VM queued" and a Cancel button for good: the delete takes the user's ownership, so the resource's job list answers 404, and outcomes were asked for only after a list answered. A 403 or 404 list now counts as an empty one, so each job is asked for by its id: while it runs (a delete goes on with the disks after the VM's record is gone) it stays shown with its Cancel button, and once it ends its page (the VM list) opens. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- operations/static/operations/job_panel.js | 25 +++++++++++++++++++---- operations/tests/js/job_panel.test.js | 19 +++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/operations/static/operations/job_panel.js b/operations/static/operations/job_panel.js index d963c06d..419b663a 100644 --- a/operations/static/operations/job_panel.js +++ b/operations/static/operations/job_panel.js @@ -18,6 +18,7 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { var inflight = {}; // id -> true: its outcome is being fetched var dismissed = {}; // id -> true: never shown again var outcomes = {}; // id -> finished job, until dismissed + var unlisted = {}; // id -> active job asked for by its id, not in the list (its resource gone) var cancelling = {}; // id -> true: its cancel request runs var notice = ""; // why the last cancel failed, until dismissed (initialIds || []).forEach(function (id) { pending[id] = true; }); @@ -88,6 +89,7 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { + esc(notice) + '
") : ""; last.jobs.forEach(function (job) { html += jobHtml(job); }); + Object.keys(unlisted).forEach(function (id) { html += jobHtml(unlisted[id]); }); Object.keys(outcomes).forEach(function (id) { html += outcomeHtml(outcomes[id]); }); last.others.forEach(function (o) { html += '
' + header(o.label, o.state, "", "") + "
"; @@ -135,9 +137,15 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { .done(function (job) { if (dismissed[id]) { delete pending[id]; return; } // still active: pending until a list shows it (one older than the job may not) or it - // ends; the next poll asks for it again - if (["queued", "running", "cancelling"].indexOf(job.state) >= 0) { return; } + // ends; the next poll asks for it again. It is shown meanwhile: a deleted VM's job + // goes on (its disks) after the VM's record, and so its list, is gone + if (["queued", "running", "cancelling"].indexOf(job.state) >= 0) { + unlisted[id] = job; + render(); + return; + } delete pending[id]; + delete unlisted[id]; // only when no other job runs, is shown or awaited: a reload would lose its outcome var others = Object.keys(outcomes).length + Object.keys(pending).length + Object.keys(shown).length; // the page in use (poll.js): its outcome waits in the panel, with Refresh @@ -158,6 +166,7 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { // not allowed or gone: asking again cannot help; a network error or 5xx can pass if (xhr.status === 403 || xhr.status === 404) { delete pending[id]; + delete unlisted[id]; render(); } }) @@ -168,7 +177,7 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { var now = {}; data.jobs.forEach(function (job) { now[job.id] = job; }); Object.keys(shown).forEach(function (id) { if (!now[id]) { pending[id] = true; } }); - Object.keys(now).forEach(function (id) { delete pending[id]; }); + Object.keys(now).forEach(function (id) { delete pending[id]; delete unlisted[id]; }); shown = now; last = data; Object.keys(pending).forEach(fetchOutcome); @@ -201,7 +210,15 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { }); } - var poller = pollWhileVisible(3000, function () { return $.getJSON(urls.resource); }, onData, 0); + var poller = pollWhileVisible(3000, function () { + return $.getJSON(urls.resource).fail(function (xhr) { + // the resource is gone (an owner's VM deleted) or no longer the user's: its jobs are + // not listed any more, so each one's outcome is asked for by its id + if (xhr.status === 403 || xhr.status === 404) { + onData(Object.assign({}, last, { jobs: [], others: [] })); + } + }); + }, onData, 0); // follow a job the page just started, as a remembered one poller.track = function (id) { pending[id] = true; diff --git a/operations/tests/js/job_panel.test.js b/operations/tests/js/job_panel.test.js index 8a769948..93ae64aa 100644 --- a/operations/tests/js/job_panel.test.js +++ b/operations/tests/js/job_panel.test.js @@ -361,3 +361,22 @@ console.log("ok"); assert.ok(elt.innerHTML.includes('çalışıyor') && elt.innerHTML.includes(">İptal"), "labels and texts of the page's language"); } + +// the resource is gone (an owner deleted the VM, which takes its ownership): the list answers 404, +// the job's outcome is asked for by its id, and its page opens +open = []; timers = []; +window.backgroundJobRunning = false; window.opened = undefined; +const elGone = { innerHTML: "", addEventListener() {} }; +jobPanel(elGone, urls, "tok", undefined, STATES, TEXT); +advance(0); +answer("/r", { ...empty, jobs: [{ ...running, id: "f", label: "Delete VM", state: "queued" }] }); +advance(3000); +answer("/r", { status: 404 }, false); +// its disks are still being deleted: the job stays shown, with its Cancel button +answer("/j/f", { ...running, id: "f", label: "Delete VM", state: "running", cancellable: true }); +assert.ok(elGone.innerHTML.includes("Delete VM") && elGone.innerHTML.includes('data-cancel="f"'), + "an active job whose resource is gone stays shown"); +advance(3000); +answer("/r", { status: 404 }, false); +answer("/j/f", { ...running, id: "f", label: "Delete VM", state: "succeeded", result: { open: "/instances/" } }); +assert.strictEqual(window.opened, "/instances/", "the outcome of a job whose resource is gone is shown");