From be507be3a90c20144e6c43d8238ca18f03e8bb88 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 22 Sep 2022 09:47:25 +0200 Subject: [PATCH] feat: refresh resource status on dashboard --- apps/ui/src/routes/index.svelte | 106 ++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 32 deletions(-) diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelte index 08cffc0ae..15ba421ad 100644 --- a/apps/ui/src/routes/index.svelte +++ b/apps/ui/src/routes/index.svelte @@ -31,7 +31,7 @@ import { get } from '$lib/api'; import { t } from '$lib/translations'; import { asyncSleep, getRndInteger } from '$lib/common'; - import { appSession, search, addToast} from '$lib/store'; + import { appSession, search } from '$lib/store'; import ApplicationsIcons from '$lib/components/svg/applications/ApplicationIcons.svelte'; import DatabaseIcons from '$lib/components/svg/databases/DatabaseIcons.svelte'; @@ -42,6 +42,25 @@ let numberOfGetStatus = 0; let status: any = {}; doSearch(); + + async function refreshStatusApplications() { + numberOfGetStatus = 0; + for (const application of applications) { + getStatus(application, true); + } + } + async function refreshStatusServices() { + numberOfGetStatus = 0; + for (const service of services) { + getStatus(service, true); + } + } + async function refreshStatusDatabases() { + numberOfGetStatus = 0; + for (const database of databases) { + getStatus(database, true); + } + } function setInitials(onlyOthers: boolean = false) { return { applications: @@ -87,12 +106,17 @@ filtered.otherDestinations = []; } - - async function getStatus(resources: any) { - const { id, buildPack, dualCerts } = resources; - if (status[id]) return status[id]; + async function getStatus(resources: any, force: boolean = false) { + const { id, buildPack, dualCerts, type } = resources; + if (buildPack && applications.length > 10 && !force) { + return; + } + if (type && services.length > 10 && !force) { + return; + } + if (status[id] && !force) return status[id]; while (numberOfGetStatus > 1) { - await asyncSleep(getRndInteger(100, 200)); + await asyncSleep(getRndInteger(100, 500)); } try { numberOfGetStatus++; @@ -118,6 +142,7 @@ status[id] = 'error'; return 'error'; } finally { + status = { ...status }; numberOfGetStatus--; } } @@ -275,7 +300,6 @@ filtered = setInitials(); } } -