diff --git a/packages/frontend/src/components/BackgroundJobProgress.tsx b/packages/frontend/src/components/BackgroundJobProgress.tsx index 0d08576..810fe6f 100644 --- a/packages/frontend/src/components/BackgroundJobProgress.tsx +++ b/packages/frontend/src/components/BackgroundJobProgress.tsx @@ -98,7 +98,7 @@ export const BackgroundJobProgress: React.FC = ({ clearInterval(intervalRef.current); } - intervalRef.current = setInterval(async () => { + const tick = async () => { try { // Always reload job list to detect newly started jobs const jobsData = await api.getAllJobs(); @@ -116,13 +116,23 @@ export const BackgroundJobProgress: React.FC = ({ } catch (err) { // ignore transient polling errors } - }, 2000); + }; + + // Adaptive interval: 2s if active jobs, else 10s + const schedule = async () => { + await tick(); + const hasActive = (jobs || []).some(j => j.status === 'running'); + const delay = hasActive ? 2000 : 10000; + intervalRef.current = setTimeout(schedule, delay) as any; + }; + + schedule(); }; // Stop polling const stopPolling = () => { if (intervalRef.current) { - clearInterval(intervalRef.current); + clearTimeout(intervalRef.current as any); intervalRef.current = null; } };