Check backend connection at intervals, not just on startup
This commit is contained in:
parent
4aff0ed5e0
commit
1304bc750a
@ -12,24 +12,35 @@ export default function App(){
|
|||||||
const [showQueue, setShowQueue] = React.useState(false);
|
const [showQueue, setShowQueue] = React.useState(false);
|
||||||
const [lastMangaListUpdate, setLastMangaListUpdate] = React.useState<Date>(new Date());
|
const [lastMangaListUpdate, setLastMangaListUpdate] = React.useState<Date>(new Date());
|
||||||
const [lastJobListUpdate, setLastJobListUpdate] = React.useState<Date>(new Date());
|
const [lastJobListUpdate, setLastJobListUpdate] = React.useState<Date>(new Date());
|
||||||
|
const [joblistUpdateInterval, setJoblistUpdateInterval] = React.useState<number>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getData('http://127.0.0.1:6531/v2/Ping').then((result) => {
|
checkConnection();
|
||||||
console.log(result);
|
setInterval(() => {
|
||||||
if(result === null){
|
checkConnection();
|
||||||
setConnected(false);
|
}, 500);
|
||||||
}else{
|
|
||||||
setConnected(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
setLastJobListUpdate(new Date());
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const checkConnection = () =>{
|
||||||
|
getData('http://127.0.0.1:6531/v2/Ping').then((result) => {
|
||||||
|
setConnected(result != null);
|
||||||
|
}).catch(() => setConnected(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if(connected){
|
||||||
|
setLastJobListUpdate(new Date());
|
||||||
|
setJoblistUpdateInterval(setInterval(() => {
|
||||||
|
setLastJobListUpdate(new Date());
|
||||||
|
}, 5000));
|
||||||
|
}else{
|
||||||
|
clearInterval(joblistUpdateInterval);
|
||||||
|
setJoblistUpdateInterval(undefined);
|
||||||
|
}
|
||||||
|
}, [connected]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const JobsChanged : EventHandler<any> = () => {
|
const JobsChanged : EventHandler<any> = () => {
|
||||||
setLastMangaListUpdate(new Date());
|
setLastMangaListUpdate(new Date());
|
||||||
setLastJobListUpdate(new Date());
|
setLastJobListUpdate(new Date());
|
||||||
|
Loading…
Reference in New Issue
Block a user