fix(ui): stale workflow responses no longer overwrite newer ones (#1949)
This commit is contained in:
3 files changed
+14
-5
No files matched your search
@@ -58,7 +58,7 @@ async function load(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => [props.taskId, props.attempt], () => { events.value = undefined; void load(); }, { immediate: true });
|
watch(() => [props.taskId, props.attempt], () => { events.value = undefined; failed.value = false; void load(); }, { immediate: true });
|
||||||
watch(() => props.running, (running) => {
|
watch(() => props.running, (running) => {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
if (running) timer = setInterval(() => void load(), 3000);
|
if (running) timer = setInterval(() => void load(), 3000);
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ const paths = computed(() => payloadPaths(payload.value));
|
|||||||
|
|
||||||
const fields = computed(() => mappingFields(inputs.value, rows.value, repository.value ? repositoryPath.value : ""));
|
const fields = computed(() => mappingFields(inputs.value, rows.value, repository.value ? repositoryPath.value : ""));
|
||||||
let previewTimer: ReturnType<typeof setTimeout> | undefined;
|
let previewTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
let previewGeneration = 0;
|
||||||
watch([fields, captureId], () => {
|
watch([fields, captureId], () => {
|
||||||
clearTimeout(previewTimer);
|
clearTimeout(previewTimer);
|
||||||
if (captureId.value === null || !fields.value.length) {
|
if (captureId.value === null || !fields.value.length) {
|
||||||
@@ -147,9 +148,12 @@ watch([fields, captureId], () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const id = captureId.value;
|
const id = captureId.value;
|
||||||
|
// Only the newest request may land: an older, slower preview would show
|
||||||
|
// results for fields that have since changed.
|
||||||
|
const request = ++previewGeneration;
|
||||||
previewTimer = setTimeout(async () => {
|
previewTimer = setTimeout(async () => {
|
||||||
const result = await api.mappingPreview<Preview>(id, fields.value).catch(() => null);
|
const result = await api.mappingPreview<Preview>(id, fields.value).catch(() => null);
|
||||||
if (id === captureId.value) preview.value = result;
|
if (request === previewGeneration) preview.value = result;
|
||||||
}, 250);
|
}, 250);
|
||||||
}, { deep: true, immediate: true });
|
}, { deep: true, immediate: true });
|
||||||
|
|
||||||
|
|||||||
@@ -67,21 +67,26 @@ const loading = ref(true);
|
|||||||
const statsKnown = ref(false);
|
const statsKnown = ref(false);
|
||||||
const statsOf = (id: string) => JSON.stringify(data.value.workflows?.find((w) => w.workflow === id) ?? null);
|
const statsOf = (id: string) => JSON.stringify(data.value.workflows?.find((w) => w.workflow === id) ?? null);
|
||||||
|
|
||||||
|
// Live reloads and actions overlap; only the newest read may land.
|
||||||
|
let loadGeneration = 0;
|
||||||
async function load() {
|
async function load() {
|
||||||
|
const current = ++loadGeneration;
|
||||||
try {
|
try {
|
||||||
// The sidebar's running count and last status come from the per-workflow
|
// The sidebar's running count and last status come from the per-workflow
|
||||||
// statistics: a page of the newest tasks across every workflow would show
|
// statistics: a page of the newest tasks across every workflow would show
|
||||||
// nothing for a workflow whose runs are older than that page.
|
// nothing for a workflow whose runs are older than that page.
|
||||||
const before = statsOf(selected.value);
|
const before = statsOf(selected.value);
|
||||||
data.value = keepValue(data.value, (await api.workflows<WorkflowsResponse>()) ?? {});
|
const response = (await api.workflows<WorkflowsResponse>()) ?? {};
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
|
data.value = keepValue(data.value, response);
|
||||||
error.value = null;
|
error.value = null;
|
||||||
statsKnown.value = true;
|
statsKnown.value = true;
|
||||||
// The runs page only changes when the workflow's own statistics do.
|
// The runs page only changes when the workflow's own statistics do.
|
||||||
if (runsFor !== selected.value || statsOf(selected.value) !== before) void loadWorkflowRuns();
|
if (runsFor !== selected.value || statsOf(selected.value) !== before) void loadWorkflowRuns();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = describeError(err, errors.common.unknown);
|
if (current === loadGeneration) error.value = describeError(err, errors.common.unknown);
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
if (current === loadGeneration) loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
useLiveResource("tasks", () => void load(), 5000);
|
useLiveResource("tasks", () => void load(), 5000);
|
||||||
|
|||||||
Reference in new issue
Block a user