Skip to content

Commit 644dab1

Browse files
committed
Minor fix to timeout cleanup
1 parent bf5213b commit 644dab1

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/lib/components/jobs/JobsList.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@
121121
const updateJobsInterval = env.PUBLIC_UPDATE_JOBS_INTERVAL
122122
? parseInt(env.PUBLIC_UPDATE_JOBS_INTERVAL)
123123
: 3000;
124-
let updateJobsTimeout = null;
124+
let updateJobsTimeout = undefined;
125125
126126
async function updateJobsInBackground() {
127127
const jobsToCheck = jobs.filter((j) => j.status === 'running' || j.status === 'submitted');
128128
if (jobsToCheck.length > 0) {
129129
jobs = await jobUpdater();
130130
tableHandler.setRows(jobs);
131131
}
132+
clearTimeout(updateJobsTimeout);
132133
updateJobsTimeout = setTimeout(updateJobsInBackground, updateJobsInterval);
133134
}
134135
@@ -137,9 +138,7 @@
137138
});
138139
139140
onDestroy(() => {
140-
if (updateJobsTimeout) {
141-
clearTimeout(updateJobsTimeout);
142-
}
141+
clearTimeout(updateJobsTimeout);
143142
});
144143
</script>
145144

src/routes/projects/[projectId]/workflows/experimental/[workflowId]/+page.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import { env } from '$env/dynamic/public';
3-
import { onMount } from 'svelte';
3+
import { onDestroy, onMount } from 'svelte';
44
import { writable } from 'svelte/store';
55
import { beforeNavigate } from '$app/navigation';
66
import { page } from '$app/stores';
@@ -498,15 +498,15 @@
498498
const runningOrSubmitted = Object.values(statuses).filter(
499499
(s) => s === 'running' || s === 'submitted'
500500
);
501-
if (statusWatcherTimer) {
502-
if (runningOrSubmitted.length === 0) {
503-
clearTimeout(statusWatcherTimer);
504-
statusWatcherTimer = undefined;
505-
}
506-
} else if (runningOrSubmitted.length > 0) {
507-
statusWatcherTimer = setInterval(loadJobsStatus, updateJobsInterval);
501+
if (runningOrSubmitted.length > 0) {
502+
clearTimeout(statusWatcherTimer);
503+
statusWatcherTimer = setTimeout(loadJobsStatus, updateJobsInterval);
508504
}
509505
}
506+
507+
onDestroy(() => {
508+
clearTimeout(statusWatcherTimer);
509+
});
510510
</script>
511511

512512
<div class="row">

0 commit comments

Comments
 (0)