fix(frontend): evitar erro por 409 em processamento (StrictMode)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import Header from './components/Header';
|
import Header from './components/Header';
|
||||||
import ConsultorCard from './components/ConsultorCard';
|
import ConsultorCard from './components/ConsultorCard';
|
||||||
import CompararModal from './components/CompararModal';
|
import CompararModal from './components/CompararModal';
|
||||||
@@ -11,6 +11,7 @@ function App() {
|
|||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [processing, setProcessing] = useState(false);
|
const [processing, setProcessing] = useState(false);
|
||||||
const [processMessage, setProcessMessage] = useState('');
|
const [processMessage, setProcessMessage] = useState('');
|
||||||
|
const processStartedRef = useRef(false);
|
||||||
const [total, setTotal] = useState(0);
|
const [total, setTotal] = useState(0);
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(50);
|
const [pageSize, setPageSize] = useState(50);
|
||||||
@@ -58,16 +59,30 @@ function App() {
|
|||||||
if (status === 503) {
|
if (status === 503) {
|
||||||
try {
|
try {
|
||||||
setProcessing(true);
|
setProcessing(true);
|
||||||
|
if (!processStartedRef.current) {
|
||||||
|
processStartedRef.current = true;
|
||||||
setProcessMessage('Ranking ainda não processado. Iniciando processamento...');
|
setProcessMessage('Ranking ainda não processado. Iniciando processamento...');
|
||||||
|
try {
|
||||||
await rankingService.processarRanking(true);
|
await rankingService.processarRanking(true);
|
||||||
|
} catch (e) {
|
||||||
|
const st = e?.response?.status;
|
||||||
|
if (st !== 409) throw e; // 409 = job já em execução (ex.: StrictMode)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setProcessMessage('Processamento do ranking já iniciado. Aguardando...');
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
try {
|
||||||
const st = await rankingService.getStatus();
|
const st = await rankingService.getStatus();
|
||||||
setProcessMessage(st.mensagem || `Processando... ${st.progress || 0}%`);
|
setProcessMessage(st.mensagem || `Processando... ${st.progress || 0}%`);
|
||||||
if (!st.running) {
|
if (!st.running) {
|
||||||
if (st.erro) throw new Error(st.erro);
|
if (st.erro) throw new Error(st.erro);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setProcessMessage('Aguardando status do processamento...');
|
||||||
|
}
|
||||||
await new Promise((r) => setTimeout(r, 4000));
|
await new Promise((r) => setTimeout(r, 4000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user