fix(background-jobs): poll job list continuously so newly started jobs appear immediately in the floating widget
This commit is contained in:
parent
7618c40a77
commit
9c8bf11986
@ -92,25 +92,31 @@ export const BackgroundJobProgress: React.FC<BackgroundJobProgressProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// Start polling for all active jobs
|
||||
// Start polling for jobs and update progress
|
||||
const startPolling = () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
}
|
||||
|
||||
intervalRef.current = setInterval(() => {
|
||||
// Update all active jobs
|
||||
const activeJobs = jobs.filter(job => job.status === 'running');
|
||||
const activeJobIds = activeJobs.map(job => job.jobId);
|
||||
activeJobIds.forEach(jobId => {
|
||||
updateJobProgress(jobId);
|
||||
});
|
||||
|
||||
// Also update specific jobId if provided
|
||||
if (jobId) {
|
||||
updateJobProgress(jobId);
|
||||
intervalRef.current = setInterval(async () => {
|
||||
try {
|
||||
// Always reload job list to detect newly started jobs
|
||||
const jobsData = await api.getAllJobs();
|
||||
setJobs(jobsData);
|
||||
|
||||
// Update progress for active jobs
|
||||
const activeJobIds = jobsData.filter((j: JobProgress) => j.status === 'running').map((j: JobProgress) => j.jobId);
|
||||
for (const id of activeJobIds) {
|
||||
await updateJobProgress(id);
|
||||
}
|
||||
|
||||
if (jobId) {
|
||||
await updateJobProgress(jobId);
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore transient polling errors
|
||||
}
|
||||
}, 2000); // Poll every 2 seconds for less frequent updates
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
// Stop polling
|
||||
@ -121,23 +127,13 @@ export const BackgroundJobProgress: React.FC<BackgroundJobProgressProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// Load jobs on mount
|
||||
// Start polling on mount and stop on unmount
|
||||
useEffect(() => {
|
||||
loadJobs();
|
||||
startPolling();
|
||||
return () => stopPolling();
|
||||
}, []);
|
||||
|
||||
// Start polling for active jobs
|
||||
useEffect(() => {
|
||||
const activeJobs = jobs.filter(job => job.status === 'running');
|
||||
if (activeJobs.length > 0 || jobId) {
|
||||
startPolling();
|
||||
}
|
||||
|
||||
return () => {
|
||||
stopPolling();
|
||||
};
|
||||
}, [jobs, jobId]);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user