This commit is contained in:
Andras Bacsai 2023-04-28 15:37:09 +02:00
parent 4c999c3ff2
commit 7377f80bdd

View File

@ -28,15 +28,17 @@
@auth @auth
<script> <script>
function checkIfIamDead() { function checkIfIamDead() {
checkIfIamDeadInterval = setInterval(async () => {
console.log('Checking server\'s pulse...') console.log('Checking server\'s pulse...')
checkIfIamDeadInterval = setInterval(async () => {
try {
const res = await fetch('/api/health'); const res = await fetch('/api/health');
if (!res.ok) { if (res.ok) {
console.log('I\'m alive. Waiting for server to be dead...');
}
} catch (error) {
console.log('I\'m dead. Charging... Standby... Bzz... Bzz...') console.log('I\'m dead. Charging... Standby... Bzz... Bzz...')
checkHealth(); checkHealth();
if (checkIfIamDeadInterval) clearInterval(checkIfIamDeadInterval); if (checkIfIamDeadInterval) clearInterval(checkIfIamDeadInterval);
} else {
console.log('I\'m alive. Waiting for server to be dead...');
} }
return; return;
@ -44,16 +46,19 @@
} }
function checkHealth() { function checkHealth() {
checkHealthInterval = setInterval(async () => {
console.log('Checking server\'s health...') console.log('Checking server\'s health...')
checkHealthInterval = setInterval(async () => {
try {
const res = await fetch('/api/health'); const res = await fetch('/api/health');
if (res.ok) { if (res.ok) {
console.log('Server is back online. Reloading...') console.log('Server is back online. Reloading...')
if (checkHealthInterval) clearInterval(checkHealthInterval); if (checkHealthInterval) clearInterval(checkHealthInterval);
window.location.reload(); window.location.reload();
} else { }
} catch (error) {
console.log('Waiting for server to come back from dead...'); console.log('Waiting for server to come back from dead...');
} }
return; return;
}, 2000); }, 2000);
} }