diff --git a/frontend/src/lib/components/FlowJobResult.svelte b/frontend/src/lib/components/FlowJobResult.svelte index cd83372389..6160ebe45b 100644 --- a/frontend/src/lib/components/FlowJobResult.svelte +++ b/frontend/src/lib/components/FlowJobResult.svelte @@ -29,17 +29,22 @@ $: jobId != lastJobId && diffJobId() + let iteration = 0 + let logOffset = 0 + async function diffJobId() { if (jobId != lastJobId) { lastJobId = jobId logs = undefined logOffset = 0 + iteration = 0 getLogs() } } - let logOffset = 0 async function getLogs() { + console.log('getLogs', iteration, jobId) + iteration += 1 if (jobId) { const getUpdate = await JobService.getJobUpdates({ workspace: workspaceId ?? $workspaceStore!, @@ -51,11 +56,14 @@ logOffset = getUpdate.log_offset ?? 0 } if (refreshLog) { - setTimeout(() => { - if (refreshLog) { - getLogs() - } - }, 1000) + setTimeout( + () => { + if (refreshLog) { + getLogs() + } + }, + iteration < 10 ? 1000 : iteration < 20 ? 2000 : 5000 + ) } } diff --git a/frontend/src/lib/components/FlowStatusViewerInner.svelte b/frontend/src/lib/components/FlowStatusViewerInner.svelte index 5f9faa8ed9..cbd1f9bfbd 100644 --- a/frontend/src/lib/components/FlowStatusViewerInner.svelte +++ b/frontend/src/lib/components/FlowStatusViewerInner.svelte @@ -88,7 +88,7 @@ flowJobIds?.flowJobs?.map((x, id) => `iter #${id + 1} not loaded by frontend yet`) ?? [] let retry_selected = '' - let timeout: NodeJS.Timeout + let timeout: NodeJS.Timeout | undefined = undefined let localModuleStates: Writable> = writable({}) let localDurationStatuses: Writable> = writable({}) @@ -403,7 +403,7 @@ } } - $: isForloopSelected && globalModuleStates && loadJobInProgress() + $: isForloopSelected && globalModuleStates && debounceLoadJobInProgress() async function getNewJob(jobId: string, initialJob: Job | undefined) { if ( @@ -421,10 +421,33 @@ } } + let debounceJobId: string | undefined = undefined + let lastRefreshed: Date | undefined = undefined + function debounceLoadJobInProgress() { + const pollingRate = reducedPolling ? 5000 : 1000 + if ( + lastRefreshed && + new Date().getTime() - lastRefreshed.getTime() < pollingRate && + debounceJobId == jobId + ) { + timeout && clearTimeout(timeout) + } + timeout = setTimeout(() => { + loadJobInProgress() + lastRefreshed = new Date() + debounceJobId = jobId + timeout = undefined + }, pollingRate) + } + let errorCount = 0 let notAnonynmous = false + let started = false async function loadJobInProgress() { - dispatch('start') + if (!started) { + started = true + dispatch('start') + } if (jobId != '00000000-0000-0000-0000-000000000000') { try { const newJob = await getNewJob(jobId, initialJob) @@ -447,7 +470,7 @@ } } if (job?.type !== 'CompletedJob' && errorCount < 4 && !destroyed) { - timeout = setTimeout(() => loadJobInProgress(), reducedPolling ? 5000 : 1000) + debounceLoadJobInProgress() } else { dispatch('done', job) } diff --git a/frontend/src/routes/(root)/(logged)/run/[...run]/+page.svelte b/frontend/src/routes/(root)/(logged)/run/[...run]/+page.svelte index 7d9d8da47c..4cc1f4c826 100644 --- a/frontend/src/routes/(root)/(logged)/run/[...run]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/run/[...run]/+page.svelte @@ -388,19 +388,20 @@ {/if} - - job?.['result'] != undefined && (viewTab = 'result')} - bind:this={testJobLoader} - bind:getLogs - bind:isLoading={testIsLoading} - bind:job - bind:jobUpdateLastFetch - workspaceOverride={$workspaceStore} - bind:notfound -/> +{#if job?.job_kind != 'flow' && job?.job_kind != 'flownode' && job?.job_kind != 'flowpreview'} + job?.['result'] != undefined && (viewTab = 'result')} + bind:this={testJobLoader} + bind:getLogs + bind:isLoading={testIsLoading} + bind:job + bind:jobUpdateLastFetch + workspaceOverride={$workspaceStore} + bind:notfound + /> +{/if}