dashboard: enhance mothership reachability checks

This commit is contained in:
Ben Allfree 2024-11-15 16:33:27 -08:00
parent a1f046bc8b
commit 78585b25b0
2 changed files with 34 additions and 35 deletions

View File

@ -3,18 +3,16 @@
</script>
{#if !$isMothershipReachable}
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
<div class="alert alert-error max-w-2xl mx-4">
<div class="text-center">
<h2 class="text-xl font-bold mb-2">Connection Lost</h2>
<p>
The PocketHost mothership is temporarily unreachable. Your instances
are safe and still reachable. Go to the <a
href="https://status.pockethost.io"
class="link font-semibold underline">status page</a
> for more information.
</p>
</div>
<div class="bg-error text-error-content p-4 rounded-none">
<div class="text-center">
<h2 class="text-xl font-bold mb-2">Connection Lost</h2>
<p>
The PocketHost mothership is temporarily unreachable. Your instances are
safe and still reachable. Go to the <a
href="https://status.pockethost.io"
class="link font-semibold underline">status page</a
> for more information.
</p>
</div>
</div>
{/if}

View File

@ -41,21 +41,33 @@ export const stats = writable<{
total_flounder_subscribers: 0,
})
const checkStats = () => {
client()
.client.send(`/api/stats`, {})
.then((res) => {
stats.set(res)
isMothershipReachable.set(true)
// setTimeout(checkStats, 1000 * 60 * 5)
})
.catch(() => {
// isMothershipReachable.set(false)
// setTimeout(checkStats, 1000)
})
}
const continuouslyCheckMothershipReachability = () => {
setInterval(() => {
client()
.client.send(`/api/health`, {})
.then((res) => {
isMothershipReachable.set(true)
})
}, 5000)
}
export const init = () => {
const { onAuthChange } = client()
const checkStats = () => {
client()
.client.send(`/api/stats`, {})
.then((res) => {
stats.set(res)
setTimeout(checkStats, 1000 * 60 * 5)
})
.catch(() => {
isMothershipReachable.set(false)
setTimeout(checkStats, 1000)
})
}
checkStats()
onAuthChange((authStoreProps) => {
@ -121,15 +133,4 @@ export const init = () => {
}
tryInstanceSubscribe()
})
setInterval(() => {
client()
.client.send(`/api/health`, {})
.then((res) => {
isMothershipReachable.set(true)
})
.catch(() => {
isMothershipReachable.set(false)
})
}, 5000)
}