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) => {
|
||||
clearInterval(timer);
|
||||
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 : ""));
|
||||
let previewTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let previewGeneration = 0;
|
||||
watch([fields, captureId], () => {
|
||||
clearTimeout(previewTimer);
|
||||
if (captureId.value === null || !fields.value.length) {
|
||||
@@ -147,9 +148,12 @@ watch([fields, captureId], () => {
|
||||
return;
|
||||
}
|
||||
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 () => {
|
||||
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);
|
||||
}, { deep: true, immediate: true });
|
||||
|
||||
|
||||
@@ -67,21 +67,26 @@ const loading = ref(true);
|
||||
const statsKnown = ref(false);
|
||||
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() {
|
||||
const current = ++loadGeneration;
|
||||
try {
|
||||
// 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
|
||||
// nothing for a workflow whose runs are older than that page.
|
||||
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;
|
||||
statsKnown.value = true;
|
||||
// The runs page only changes when the workflow's own statistics do.
|
||||
if (runsFor !== selected.value || statsOf(selected.value) !== before) void loadWorkflowRuns();
|
||||
} catch (err) {
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
if (current === loadGeneration) error.value = describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (current === loadGeneration) loading.value = false;
|
||||
}
|
||||
}
|
||||
useLiveResource("tasks", () => void load(), 5000);
|
||||
|
||||
Reference in new issue
Block a user