New Frontend
This commit is contained in:
@@ -20,6 +20,9 @@ interface UseTrainingOptions {
|
||||
export const useTraining = (options: UseTrainingOptions = {}) => {
|
||||
|
||||
const { disablePolling = false } = options;
|
||||
|
||||
// Debug logging for option changes
|
||||
console.log('🔧 useTraining initialized with options:', { disablePolling, options });
|
||||
const [jobs, setJobs] = useState<TrainingJobResponse[]>([]);
|
||||
const [currentJob, setCurrentJob] = useState<TrainingJobResponse | null>(null);
|
||||
const [models, setModels] = useState<ModelInfo[]>([]);
|
||||
@@ -193,22 +196,41 @@ export const useTraining = (options: UseTrainingOptions = {}) => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// Skip polling if disabled or no running jobs
|
||||
if (disablePolling) {
|
||||
console.log('🚫 HTTP status polling disabled - using WebSocket instead');
|
||||
return;
|
||||
// Always check disablePolling first and log for debugging
|
||||
console.log('🔍 useTraining polling check:', {
|
||||
disablePolling,
|
||||
jobsCount: jobs.length,
|
||||
runningJobs: jobs.filter(job => job.status === 'running' || job.status === 'pending').length
|
||||
});
|
||||
|
||||
// STRICT CHECK: Skip polling if disabled - NO EXCEPTIONS
|
||||
if (disablePolling === true) {
|
||||
console.log('🚫 HTTP status polling STRICTLY DISABLED - using WebSocket instead');
|
||||
console.log('🚫 Effect triggered but polling prevented by disablePolling flag');
|
||||
return; // Early return - no cleanup needed, no interval creation
|
||||
}
|
||||
|
||||
const runningJobs = jobs.filter(job => job.status === 'running' || job.status === 'pending');
|
||||
|
||||
if (runningJobs.length === 0) return;
|
||||
if (runningJobs.length === 0) {
|
||||
console.log('⏸️ No running jobs - skipping polling setup');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🔄 Starting HTTP status polling for', runningJobs.length, 'jobs');
|
||||
|
||||
const interval = setInterval(async () => {
|
||||
// Double-check disablePolling inside interval to prevent race conditions
|
||||
if (disablePolling) {
|
||||
console.log('🚫 Polling disabled during interval - clearing');
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const job of runningJobs) {
|
||||
try {
|
||||
const tenantId = job.tenant_id;
|
||||
console.log('📡 HTTP polling job status:', job.job_id);
|
||||
await getTrainingJobStatus(tenantId, job.job_id);
|
||||
} catch (error) {
|
||||
console.error('Failed to refresh job status:', error);
|
||||
@@ -217,7 +239,7 @@ export const useTraining = (options: UseTrainingOptions = {}) => {
|
||||
}, 5000); // Refresh every 5 seconds
|
||||
|
||||
return () => {
|
||||
console.log('🛑 Stopping HTTP status polling');
|
||||
console.log('🛑 Stopping HTTP status polling (cleanup)');
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [jobs, getTrainingJobStatus, disablePolling]);
|
||||
|
||||
Reference in New Issue
Block a user