This commit is contained in:
marko-kraemer 2025-08-03 01:15:56 +02:00
parent 41ee63719d
commit 286e7edeef
1 changed files with 38 additions and 2 deletions

View File

@ -277,6 +277,8 @@ export function useAgentProcessingJobs(agentId: string) {
return useQuery({
queryKey: knowledgeBaseKeys.processingJobs(agentId),
queryFn: async (): Promise<ProcessingJobsResponse> => {
console.log('📊 Fetching processing jobs for agent:', agentId);
const headers = await getHeaders();
const response = await fetch(`${API_URL}/knowledge-base/agents/${agentId}/processing-jobs`, { headers });
@ -285,9 +287,43 @@ export function useAgentProcessingJobs(agentId: string) {
throw new Error(error || 'Failed to fetch processing jobs');
}
return await response.json();
const data = await response.json();
console.log('📊 Processing jobs response:', {
agentId,
jobCount: data.jobs?.length || 0,
activeJobs: data.jobs?.filter(job => job.status === 'processing' || job.status === 'pending').length || 0
});
return data;
},
enabled: !!agentId,
refetchInterval: 5000,
// Smart polling: only poll when there are active processing jobs
refetchInterval: (query) => {
const data = query.state.data as ProcessingJobsResponse | undefined;
// If no data yet, check once after 2 seconds
if (!data) {
console.log('⏱️ No data yet, polling in 2 seconds');
return 2000;
}
// Check if there are any active processing jobs (pending or processing status)
const hasActiveJobs = data.jobs?.some(job =>
job.status === 'processing' || job.status === 'pending'
);
const nextInterval = hasActiveJobs ? 3000 : 30000;
console.log('⏱️ Polling decision:', {
hasActiveJobs,
nextInterval: `${nextInterval/1000}s`,
jobStatuses: data.jobs?.map(job => job.status) || []
});
// If there are active jobs, poll every 3 seconds
// If no active jobs, poll every 30 seconds (much less frequent)
return nextInterval;
},
// Stop polling when window is not focused to save resources
refetchIntervalInBackground: false,
});
}