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 = () => {
|
const startPolling = () => {
|
||||||
if (intervalRef.current) {
|
if (intervalRef.current) {
|
||||||
clearInterval(intervalRef.current);
|
clearInterval(intervalRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
intervalRef.current = setInterval(() => {
|
intervalRef.current = setInterval(async () => {
|
||||||
// Update all active jobs
|
try {
|
||||||
const activeJobs = jobs.filter(job => job.status === 'running');
|
// Always reload job list to detect newly started jobs
|
||||||
const activeJobIds = activeJobs.map(job => job.jobId);
|
const jobsData = await api.getAllJobs();
|
||||||
activeJobIds.forEach(jobId => {
|
setJobs(jobsData);
|
||||||
updateJobProgress(jobId);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Also update specific jobId if provided
|
// Update progress for active jobs
|
||||||
if (jobId) {
|
const activeJobIds = jobsData.filter((j: JobProgress) => j.status === 'running').map((j: JobProgress) => j.jobId);
|
||||||
updateJobProgress(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
|
// 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(() => {
|
useEffect(() => {
|
||||||
loadJobs();
|
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
|
// Cleanup on unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user