perf(jobs): adaptive polling (2s with active jobs, 10s when idle)
This commit is contained in:
parent
3f57904dd7
commit
6eabfdedd0
@ -98,7 +98,7 @@ export const BackgroundJobProgress: React.FC<BackgroundJobProgressProps> = ({
|
|||||||
clearInterval(intervalRef.current);
|
clearInterval(intervalRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
intervalRef.current = setInterval(async () => {
|
const tick = async () => {
|
||||||
try {
|
try {
|
||||||
// Always reload job list to detect newly started jobs
|
// Always reload job list to detect newly started jobs
|
||||||
const jobsData = await api.getAllJobs();
|
const jobsData = await api.getAllJobs();
|
||||||
@ -116,13 +116,23 @@ export const BackgroundJobProgress: React.FC<BackgroundJobProgressProps> = ({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// ignore transient polling errors
|
// 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
|
// Stop polling
|
||||||
const stopPolling = () => {
|
const stopPolling = () => {
|
||||||
if (intervalRef.current) {
|
if (intervalRef.current) {
|
||||||
clearInterval(intervalRef.current);
|
clearTimeout(intervalRef.current as any);
|
||||||
intervalRef.current = null;
|
intervalRef.current = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user