Add base kubernetes support final fix 4

This commit is contained in:
Urtzi Alfaro
2025-09-29 07:54:25 +02:00
parent 57f77638cc
commit 4777e59e7a
14 changed files with 1041 additions and 167 deletions

View File

@@ -94,18 +94,21 @@ export const OnboardingWizard: React.FC = () => {
const { setCurrentTenant } = useTenantActions();
// Auto-complete user_registered step if needed (runs first)
const [autoCompletionAttempted, setAutoCompletionAttempted] = React.useState(false);
useEffect(() => {
if (userProgress && user?.id) {
if (userProgress && user?.id && !autoCompletionAttempted && !markStepCompleted.isPending) {
const userRegisteredStep = userProgress.steps.find(s => s.step_name === 'user_registered');
if (!userRegisteredStep?.completed) {
console.log('🔄 Auto-completing user_registered step for new user...');
setAutoCompletionAttempted(true);
markStepCompleted.mutate({
userId: user.id,
stepName: 'user_registered',
data: {
auto_completed: true,
data: {
auto_completed: true,
completed_at: new Date().toISOString(),
source: 'onboarding_wizard_auto_completion'
}
@@ -116,11 +119,13 @@ export const OnboardingWizard: React.FC = () => {
},
onError: (error) => {
console.error('❌ Failed to auto-complete user_registered step:', error);
// Reset flag on error to allow retry
setAutoCompletionAttempted(false);
}
});
}
}
}, [userProgress, user?.id, markStepCompleted]);
}, [userProgress, user?.id, autoCompletionAttempted, markStepCompleted.isPending]); // Removed markStepCompleted from deps
// Initialize step index based on backend progress with validation
useEffect(() => {
@@ -205,6 +210,12 @@ export const OnboardingWizard: React.FC = () => {
return;
}
// Prevent concurrent mutations
if (markStepCompleted.isPending) {
console.warn(`⚠️ Step completion already in progress for "${currentStep.id}", skipping duplicate call`);
return;
}
console.log(`🎯 Completing step: "${currentStep.id}" with data:`, data);
try {
@@ -260,25 +271,50 @@ export const OnboardingWizard: React.FC = () => {
}
} catch (error: any) {
console.error(`❌ Error completing step "${currentStep.id}":`, error);
// Extract detailed error information
const errorMessage = error?.response?.data?.detail || error?.message || 'Unknown error';
const statusCode = error?.response?.status;
console.error(`📊 Error details: Status ${statusCode}, Message: ${errorMessage}`);
// Handle different types of errors
if (statusCode === 207) {
// Multi-Status: Step updated but summary failed
console.warn(`⚠️ Partial success for step "${currentStep.id}": ${errorMessage}`);
// Continue with step advancement since the actual step was completed
if (currentStep.id === 'completion') {
// Navigate to dashboard after completion
if (isNewTenant) {
navigate('/app/dashboard');
} else {
navigate('/app');
}
} else {
// Auto-advance to next step after successful completion
if (currentStepIndex < STEPS.length - 1) {
setCurrentStepIndex(currentStepIndex + 1);
}
}
// Show a warning but don't block progress
console.warn(`Step "${currentStep.title}" completed with warnings: ${errorMessage}`);
return; // Don't show error alert
}
// Check if it's a dependency error
if (errorMessage.includes('dependencies not met')) {
console.error('🚫 Dependencies not met for step:', currentStep.id);
// Check what dependencies are missing
if (userProgress) {
console.log('📋 Current progress:', userProgress);
console.log('📋 Completed steps:', userProgress.steps.filter(s => s.completed).map(s => s.step_name));
}
}
// Don't advance automatically on error - user should see the issue
// Don't advance automatically on real errors - user should see the issue
alert(`${t('onboarding:errors.step_failed', 'Error al completar paso')} "${currentStep.title}": ${errorMessage}`);
}
};

View File

@@ -1,7 +1,7 @@
import React, { useState, useCallback, useEffect } from 'react';
import { Button } from '../../../ui/Button';
import { useCurrentTenant } from '../../../../stores/tenant.store';
import { useCreateTrainingJob, useTrainingWebSocket } from '../../../../api/hooks/training';
import { useCreateTrainingJob, useTrainingWebSocket, useTrainingJobStatus } from '../../../../api/hooks/training';
interface MLTrainingStepProps {
onNext: () => void;
@@ -85,6 +85,63 @@ export const MLTrainingStep: React.FC<MLTrainingStepProps> = ({
} : undefined
);
// Smart fallback polling - automatically disabled when WebSocket is connected
const { data: jobStatus } = useTrainingJobStatus(
currentTenant?.id || '',
jobId || '',
{
enabled: !!jobId && !!currentTenant?.id,
isWebSocketConnected: isConnected, // This will disable HTTP polling when WebSocket is connected
}
);
// Handle training status updates from HTTP polling (fallback only)
useEffect(() => {
if (!jobStatus || !jobId || trainingProgress?.stage === 'completed') {
return;
}
console.log('📊 HTTP fallback status update:', jobStatus);
// Check if training completed via HTTP polling fallback
if (jobStatus.status === 'completed' && trainingProgress?.stage !== 'completed') {
console.log('✅ Training completion detected via HTTP fallback');
setTrainingProgress({
stage: 'completed',
progress: 100,
message: 'Entrenamiento completado exitosamente (detectado por verificación HTTP)'
});
setIsTraining(false);
setTimeout(() => {
onComplete({
jobId: jobId,
success: true,
message: 'Modelo entrenado correctamente',
detectedViaPolling: true
});
}, 2000);
} else if (jobStatus.status === 'failed') {
console.log('❌ Training failure detected via HTTP fallback');
setError('Error detectado durante el entrenamiento (verificación de estado)');
setIsTraining(false);
setTrainingProgress(null);
} else if (jobStatus.status === 'running' && jobStatus.progress !== undefined) {
// Update progress if we have newer information from HTTP polling fallback
const currentProgress = trainingProgress?.progress || 0;
if (jobStatus.progress > currentProgress) {
console.log(`📈 Progress update via HTTP fallback: ${jobStatus.progress}%`);
setTrainingProgress(prev => ({
...prev,
stage: 'training',
progress: jobStatus.progress,
message: jobStatus.message || 'Entrenando modelo...',
currentStep: jobStatus.current_step
}) as TrainingProgress);
}
}
}, [jobStatus, jobId, trainingProgress?.stage, onComplete]);
// Auto-trigger training when component mounts
useEffect(() => {
if (currentTenant?.id && !isTraining && !trainingProgress && !error) {