Add cooperative task recovery and persistent live status
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 40s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 49s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 1m37s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 36s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 42s
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 40s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 49s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 1m37s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 36s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 42s
This commit is contained in:
1 parent
034fecbd51
commit
3bfd199b9c
28 files changed
+2356
-172
No files matched your search
+200
-78
@@ -3,7 +3,7 @@ const output = document.querySelector("#run-output");
|
||||
if (output) {
|
||||
let offset = Number(output.dataset.outputOffset || 0);
|
||||
let detailsFinalized = !["queued", "running"].includes(
|
||||
document.querySelector("#run-status")?.textContent.trim(),
|
||||
document.querySelector("#run-status")?.dataset.runStatus,
|
||||
);
|
||||
const refresh = async () => {
|
||||
let delay = 2000;
|
||||
@@ -24,7 +24,12 @@ if (output) {
|
||||
offset = state.offset;
|
||||
const status = document.querySelector("#run-status");
|
||||
if (status) {
|
||||
status.textContent = state.status;
|
||||
status.textContent = state.display_status;
|
||||
status.dataset.runStatus = state.status;
|
||||
const progress = document.querySelector("#run-progress");
|
||||
if (progress && progress.textContent !== (state.progress || "—")) {
|
||||
progress.textContent = state.progress || "—";
|
||||
}
|
||||
if (state.has_more) {
|
||||
delay = 0;
|
||||
} else if (state.status !== "queued" && state.status !== "running") {
|
||||
@@ -42,6 +47,7 @@ if (output) {
|
||||
document.querySelectorAll(actions).forEach((form) => form.remove());
|
||||
status.closest("dl").replaceWith(nextDetails);
|
||||
nextDetails.after(...page.querySelectorAll(actions));
|
||||
initializeTaskForms(page);
|
||||
detailsFinalized = true;
|
||||
}
|
||||
const artifacts = document.querySelector("#run-artifacts");
|
||||
@@ -115,98 +121,135 @@ for (const choice of document.querySelectorAll("button[data-execution-choice]"))
|
||||
});
|
||||
}
|
||||
|
||||
for (const form of document.querySelectorAll("form[data-wait-for-result]")) {
|
||||
const result = form.querySelector(".task-result");
|
||||
const controls = [...form.querySelectorAll("input, select, button")];
|
||||
let waiting = false;
|
||||
const activeStatus = (status) => status === "queued" || status === "running";
|
||||
const taskControllers = new Map();
|
||||
let tasksStateUrl;
|
||||
let taskStateVersion = 0;
|
||||
let refreshingTasks = false;
|
||||
let taskRefreshTimer;
|
||||
|
||||
const warnBeforeLeaving = (event) => {
|
||||
event.preventDefault();
|
||||
event.returnValue = "";
|
||||
};
|
||||
|
||||
const setWaiting = (value) => {
|
||||
waiting = value;
|
||||
form.classList.toggle("is-waiting", value);
|
||||
controls.forEach((control) => {
|
||||
control.disabled = value;
|
||||
});
|
||||
form.querySelectorAll("details.split-menu").forEach((menu) => {
|
||||
menu.open = false;
|
||||
});
|
||||
if (value) {
|
||||
window.addEventListener("beforeunload", warnBeforeLeaving);
|
||||
} else {
|
||||
window.removeEventListener("beforeunload", warnBeforeLeaving);
|
||||
}
|
||||
};
|
||||
|
||||
const showResult = (message, kind, detailUrl) => {
|
||||
result.replaceChildren();
|
||||
result.className = `task-result ${kind}`;
|
||||
result.append(message);
|
||||
if (detailUrl) {
|
||||
const link = document.createElement("a");
|
||||
link.href = detailUrl;
|
||||
link.textContent = "View details";
|
||||
result.append(" ", link);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadArtifacts = async (run) => {
|
||||
const response = await fetch(run.artifacts_url, { cache: "no-store" });
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
const artifacts = (await response.json()).artifacts;
|
||||
const artifact = artifacts.find((item) => !item.view_url);
|
||||
if (!artifact) {
|
||||
return;
|
||||
}
|
||||
const downloadArtifacts = async (run) => {
|
||||
const response = await fetch(run.artifacts_url, { cache: "no-store" });
|
||||
if (!response.ok) {
|
||||
throw new Error("Could not read task downloads. Open the run details to download them.");
|
||||
}
|
||||
const artifact = (await response.json()).artifacts.find((item) => !item.view_url);
|
||||
if (artifact) {
|
||||
const link = document.createElement("a");
|
||||
link.href = artifact.url;
|
||||
link.download = "";
|
||||
document.body.append(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
}
|
||||
};
|
||||
|
||||
function taskController(form, initialState) {
|
||||
const result = form.querySelector(".task-result");
|
||||
const message = result.querySelector(".task-message");
|
||||
const progress = result.querySelector(".task-progress");
|
||||
let state = initialState;
|
||||
let observedRun = state.active_run;
|
||||
let submitting = false;
|
||||
let lastResult;
|
||||
let previousMessage;
|
||||
|
||||
const render = (text, kind = "", run = null, progressText = "", suffix = "", label = "View details") => {
|
||||
const signature = JSON.stringify([text, kind, run?.detail_url, suffix, label]);
|
||||
if (signature !== previousMessage) {
|
||||
message.replaceChildren(text);
|
||||
if (run) {
|
||||
const link = document.createElement("a");
|
||||
link.href = run.detail_url;
|
||||
link.textContent = label;
|
||||
message.append(" ", link, suffix);
|
||||
}
|
||||
previousMessage = signature;
|
||||
}
|
||||
if (progress.textContent !== progressText) {
|
||||
progress.textContent = progressText;
|
||||
}
|
||||
result.className = `task-result ${kind}`;
|
||||
result.hidden = !text;
|
||||
};
|
||||
|
||||
const waitForRun = async (run) => {
|
||||
const started = Date.now();
|
||||
while (true) {
|
||||
const showState = () => {
|
||||
const active = state.active_run;
|
||||
const blocker = state.blocked_by;
|
||||
const disabled = submitting || Boolean(active || blocker);
|
||||
form.querySelector(".task-controls").disabled = disabled;
|
||||
form.classList.toggle("is-waiting", submitting || Boolean(active));
|
||||
form.setAttribute("aria-busy", String(submitting || Boolean(active)));
|
||||
form.querySelectorAll("details.split-menu").forEach((menu) => {
|
||||
menu.inert = disabled;
|
||||
if (disabled) {
|
||||
menu.open = false;
|
||||
}
|
||||
});
|
||||
if (submitting) {
|
||||
render("Starting...", "running");
|
||||
} else if (active) {
|
||||
const status = active.display_status;
|
||||
render(`${status[0].toUpperCase()}${status.slice(1)}.`, "running", active,
|
||||
state.progress, "", `Run #${active.run_id}`);
|
||||
} else if (blocker) {
|
||||
render("Blocked by", "blocked", blocker, "", ` (${blocker.display_status}).`, `run #${blocker.run_id}`);
|
||||
} else if (lastResult) {
|
||||
render(lastResult.text, lastResult.kind, lastResult.run);
|
||||
} else {
|
||||
render("");
|
||||
}
|
||||
};
|
||||
|
||||
const apply = async (nextState, version) => {
|
||||
if (submitting || version !== taskStateVersion) {
|
||||
return;
|
||||
}
|
||||
state = nextState;
|
||||
if (state.active_run) {
|
||||
observedRun = state.active_run;
|
||||
} else if (observedRun) {
|
||||
const run = observedRun;
|
||||
const response = await fetch(run.state_url, { cache: "no-store" });
|
||||
if (!response.ok) {
|
||||
throw new Error("Could not read task status.");
|
||||
}
|
||||
const state = await response.json();
|
||||
if (state.status !== "queued" && state.status !== "running") {
|
||||
if (state.status === "succeeded") {
|
||||
showResult("Completed successfully.", "succeeded", run.detail_url);
|
||||
if (form.dataset.downloadArtifacts !== undefined) {
|
||||
await downloadArtifacts(run);
|
||||
}
|
||||
} else {
|
||||
showResult(`Finished with status: ${state.status}.`, "failed", run.detail_url);
|
||||
}
|
||||
const completed = await response.json();
|
||||
if (submitting || version !== taskStateVersion) {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => window.setTimeout(resolve, Date.now() - started < 10000 ? 500 : 2000));
|
||||
if (activeStatus(completed.status)) {
|
||||
state = { ...state, active_run: completed, progress: completed.progress };
|
||||
} else {
|
||||
observedRun = null;
|
||||
lastResult = {
|
||||
text: completed.status === "succeeded" ? "Completed successfully." : `Finished with status: ${completed.status}.`,
|
||||
kind: completed.status === "succeeded" ? "succeeded" : "failed",
|
||||
run,
|
||||
};
|
||||
if (completed.status === "succeeded" && form.dataset.downloadArtifacts !== undefined) {
|
||||
try {
|
||||
await downloadArtifacts(run);
|
||||
} catch (error) {
|
||||
lastResult = { text: error.message, kind: "failed", run };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
showState();
|
||||
};
|
||||
|
||||
form.addEventListener("submit", async (event) => {
|
||||
if (waiting) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (!form.reportValidity()) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
if (submitting || state.active_run || state.blocked_by || !form.reportValidity()) {
|
||||
return;
|
||||
}
|
||||
// Disabled fields are omitted from FormData, so collect values first.
|
||||
const formData = new FormData(form);
|
||||
setWaiting(true);
|
||||
showResult("Running...", "running");
|
||||
submitting = true;
|
||||
lastResult = null;
|
||||
taskStateVersion += 1;
|
||||
showState();
|
||||
try {
|
||||
const response = await fetch(form.action, {
|
||||
method: "POST",
|
||||
@@ -214,15 +257,94 @@ for (const form of document.querySelectorAll("form[data-wait-for-result]")) {
|
||||
headers: { Accept: "application/json" },
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
const messages = data.errors ? Object.values(data.errors).join(" ") : "Could not start task.";
|
||||
throw new Error(messages);
|
||||
taskStateVersion += 1;
|
||||
if (response.status === 409 && data.blocked_by) {
|
||||
state = { active_run: null, blocked_by: data.blocked_by, progress: "" };
|
||||
} else if (!response.ok) {
|
||||
throw new Error(data.errors ? Object.values(data.errors).join(" ") : data.error || "Could not start task.");
|
||||
} else {
|
||||
observedRun = data;
|
||||
state = { active_run: data, blocked_by: null, progress: "" };
|
||||
if (form.dataset.waitForResult === undefined) {
|
||||
window.location.assign(data.detail_url);
|
||||
}
|
||||
}
|
||||
await waitForRun(data);
|
||||
} catch (error) {
|
||||
showResult(error instanceof Error ? error.message : "Could not run task.", "failed");
|
||||
lastResult = { text: error instanceof Error ? error.message : "Could not run task.", kind: "failed" };
|
||||
} finally {
|
||||
setWaiting(false);
|
||||
submitting = false;
|
||||
showState();
|
||||
refreshTaskStates();
|
||||
}
|
||||
});
|
||||
showState();
|
||||
return { apply };
|
||||
}
|
||||
|
||||
async function refreshTaskStates() {
|
||||
if (refreshingTasks || !tasksStateUrl) {
|
||||
return;
|
||||
}
|
||||
refreshingTasks = true;
|
||||
window.clearTimeout(taskRefreshTimer);
|
||||
const version = taskStateVersion;
|
||||
const errorMessage = document.querySelector("#task-status-error");
|
||||
try {
|
||||
const response = await fetch(tasksStateUrl, { cache: "no-store" });
|
||||
if (!response.ok) {
|
||||
throw new Error("Could not read live task status.");
|
||||
}
|
||||
const states = await response.json();
|
||||
for (const [form, controller] of taskControllers) {
|
||||
if (!form.isConnected) {
|
||||
taskControllers.delete(form);
|
||||
continue;
|
||||
}
|
||||
const state = form.dataset.taskId ? states.tasks[form.dataset.taskId] : states.groups[form.dataset.groupId];
|
||||
if (state) {
|
||||
await controller.apply(state, version);
|
||||
}
|
||||
}
|
||||
if (errorMessage) {
|
||||
errorMessage.hidden = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Could not refresh task status:", error);
|
||||
if (errorMessage) {
|
||||
errorMessage.textContent = "Live status unavailable. Retrying...";
|
||||
errorMessage.hidden = false;
|
||||
}
|
||||
} finally {
|
||||
refreshingTasks = false;
|
||||
if (taskControllers.size) {
|
||||
taskRefreshTimer = window.setTimeout(refreshTaskStates, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeTaskForms(source = document) {
|
||||
const data = source.querySelector("#task-states");
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
tasksStateUrl = data.dataset.stateUrl;
|
||||
const states = JSON.parse(data.textContent);
|
||||
for (const form of document.querySelectorAll("form[data-task-id], form[data-group-id]")) {
|
||||
if (!taskControllers.has(form)) {
|
||||
const state = form.dataset.taskId ? states.tasks[form.dataset.taskId] : states.groups[form.dataset.groupId];
|
||||
taskControllers.set(form, taskController(form, state));
|
||||
}
|
||||
}
|
||||
if (taskControllers.size) {
|
||||
if (!document.querySelector("#task-status-error")) {
|
||||
const errorMessage = document.createElement("p");
|
||||
errorMessage.id = "task-status-error";
|
||||
errorMessage.setAttribute("role", "status");
|
||||
errorMessage.hidden = true;
|
||||
document.querySelector("main").prepend(errorMessage);
|
||||
}
|
||||
refreshTaskStates();
|
||||
}
|
||||
}
|
||||
|
||||
initializeTaskForms();
|
||||
Reference in new issue
Block a user