Fix/0429/fix all log (#318)
* fix:fix return all log problem * fix:delete no use code * fix: add sse offset * fix: change offset to string * fix: fix more localStore * fix: change log only * fix: cancel offset * fix: remove offset * fix:delete no use code * fix:add hertbeat * fix: delete useless code --------- Co-authored-by: Ye Xiangle <yexiangle@mail.mindverse.ai>
This commit is contained in:
parent
1d79691e71
commit
c3855f37ad
|
@ -216,9 +216,6 @@ export default function TrainingPage() {
|
|||
if (trainingProgress.status === 'in_progress') {
|
||||
setIsTraining(true);
|
||||
|
||||
// Create EventSource connection to get logs
|
||||
updateTrainLog();
|
||||
|
||||
if (firstLoadRef.current) {
|
||||
scrollPageToBottom();
|
||||
|
||||
|
@ -234,19 +231,15 @@ export default function TrainingPage() {
|
|||
) {
|
||||
stopPolling();
|
||||
setIsTraining(false);
|
||||
|
||||
// Keep EventSource open to preserve received logs
|
||||
// If resource cleanup is needed, EventSource could be closed here
|
||||
}
|
||||
|
||||
// Return cleanup function to ensure EventSource is closed when component unmounts or dependencies change
|
||||
return () => {
|
||||
if (cleanupEventSourceRef.current) {
|
||||
cleanupEventSourceRef.current();
|
||||
}
|
||||
};
|
||||
}, [trainingProgress]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isTraining) {
|
||||
updateTrainLog();
|
||||
}
|
||||
}, [isTraining]);
|
||||
|
||||
// Cleanup when component unmounts
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
@ -297,7 +290,7 @@ export default function TrainingPage() {
|
|||
|
||||
const getDetails = () => {
|
||||
// Use EventSource to get logs
|
||||
const eventSource = new EventSource('/api/trainprocess/logs');
|
||||
const eventSource = new EventSource(`/api/trainprocess/logs`);
|
||||
|
||||
eventSource.onmessage = (event) => {
|
||||
// Don't try to parse as JSON, just use the raw text data directly
|
||||
|
@ -366,6 +359,7 @@ export default function TrainingPage() {
|
|||
if (res.data.code === 0) {
|
||||
setTrainSuspended(false);
|
||||
resetTrainingState();
|
||||
localStorage.removeItem('trainingLogs');
|
||||
} else {
|
||||
throw new Error(res.data.message || 'Failed to reset progress');
|
||||
}
|
||||
|
|
|
@ -126,7 +126,6 @@ def start_process():
|
|||
logger.error(f"Training process failed: {str(e)}")
|
||||
return jsonify(APIResponse.error(message=f"Training process error: {str(e)}"))
|
||||
|
||||
|
||||
@trainprocess_bp.route("/logs", methods=["GET"])
|
||||
def stream_logs():
|
||||
"""Get training logs in real-time"""
|
||||
|
@ -149,6 +148,8 @@ def stream_logs():
|
|||
yield f"data: {line.strip()}\n\n"
|
||||
|
||||
last_position = log_file.tell()
|
||||
if not new_lines:
|
||||
yield f":heartbeat\n\n"
|
||||
except Exception as e:
|
||||
# If file reading fails, record error and continue
|
||||
yield f"data: Error reading log file: {str(e)}\n\n"
|
||||
|
@ -166,7 +167,6 @@ def stream_logs():
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
@trainprocess_bp.route("/progress/<model_name>", methods=["GET"])
|
||||
def get_progress(model_name):
|
||||
"""Get current progress (non-real-time)"""
|
||||
|
|
Loading…
Reference in New Issue