From baa11ae240ea5fd51987ebe021b0b694eeddeb50 Mon Sep 17 00:00:00 2001 From: weibaohui Date: Sun, 12 Nov 2023 20:17:49 +0800 Subject: [PATCH] TimerUtils update --- src/backend/utils/TimerUtils.ts | 5 +++++ .../components/ClusterRole/ClusterRoleListView.vue | 5 +++-- .../ClusterRoleBinding/ClusterRoleBindingListView.vue | 5 +++-- .../components/EndpointSlice/EndpointSliceListView.vue | 4 ++-- .../components/HorizontalPodAutoscaler/HpaListView.vue | 4 ++-- .../components/IngressClass/IngressClassListView.vue | 4 ++-- .../MutatingWebhook/MutatingWebhookListView.vue | 4 ++-- src/frontend/components/NetworkPolicy/NetpolListView.vue | 4 ++-- .../PersistentVolume/PersistentVolumeListView.vue | 4 ++-- .../components/PersistentVolumeClaim/PvcListView.vue | 4 ++-- .../components/PodDisruptionBudget/PdbListView.vue | 4 ++-- src/frontend/components/Role/RoleListView.vue | 4 ++-- .../components/RoleBinding/RoleBindingListView.vue | 4 ++-- src/frontend/components/ServiceAccount/SaListView.vue | 4 ++-- .../components/StorageClass/StorageClassListView.vue | 4 ++-- .../ValidatingWebhook/ValidatingWebhookListView.vue | 4 ++-- src/frontend/components/configmap/CmListView.vue | 4 +--- src/frontend/components/cronjob/CronJobListView.vue | 5 +++-- src/frontend/components/daemonset/DsListView.vue | 4 ++-- src/frontend/components/deployment/DeployListView.vue | 4 ++-- src/frontend/components/endpoint/EpListView.vue | 5 ++--- src/frontend/components/event/EventListView.vue | 4 ++-- src/frontend/components/ingress/IngListView.vue | 4 ++-- src/frontend/components/job/JobListView.vue | 4 ++-- src/frontend/components/limitrange/LimitsListView.vue | 4 ++-- src/frontend/components/node/NodeListView.vue | 8 +++++--- src/frontend/components/ns/NsListView.vue | 4 ++-- src/frontend/components/pod/PodListView.vue | 5 +++-- src/frontend/components/priorityclass/PcListView.vue | 4 ++-- src/frontend/components/replicacontroller/RcListView.vue | 4 ++-- src/frontend/components/resourcequota/QuotaListView.vue | 4 ++-- src/frontend/components/secret/SecretListView.vue | 4 ++-- src/frontend/components/service/SvcListView.vue | 4 ++-- src/frontend/components/statefulset/StsListView.vue | 5 ++--- 34 files changed, 77 insertions(+), 70 deletions(-) diff --git a/src/backend/utils/TimerUtils.ts b/src/backend/utils/TimerUtils.ts index 67f17fcf..2e5df8f1 100644 --- a/src/backend/utils/TimerUtils.ts +++ b/src/backend/utils/TimerUtils.ts @@ -23,6 +23,11 @@ export class TimerUtils { return setTimeout(handler, 2000) } + static runOnceThenDelayTwoSeconds(run: () => void, handler: TimerHandler) { + run() + return setTimeout(handler, 2000) + } + static delay(handler: TimerHandler, timeout: number) { return setTimeout(handler, timeout) } diff --git a/src/frontend/components/ClusterRole/ClusterRoleListView.vue b/src/frontend/components/ClusterRole/ClusterRoleListView.vue index c91f9bb1..483766f8 100644 --- a/src/frontend/components/ClusterRole/ClusterRoleListView.vue +++ b/src/frontend/components/ClusterRole/ClusterRoleListView.vue @@ -90,8 +90,9 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(searchText.value)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ClusterRole)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.ClusterRole), + ) }) diff --git a/src/frontend/components/ClusterRoleBinding/ClusterRoleBindingListView.vue b/src/frontend/components/ClusterRoleBinding/ClusterRoleBindingListView.vue index 7756d30c..48bf718e 100644 --- a/src/frontend/components/ClusterRoleBinding/ClusterRoleBindingListView.vue +++ b/src/frontend/components/ClusterRoleBinding/ClusterRoleBindingListView.vue @@ -95,8 +95,9 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(searchText.value)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ClusterRoleBinding)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.ClusterRoleBinding), + ) }) diff --git a/src/frontend/components/EndpointSlice/EndpointSliceListView.vue b/src/frontend/components/EndpointSlice/EndpointSliceListView.vue index 4c89d120..12f8d46c 100644 --- a/src/frontend/components/EndpointSlice/EndpointSliceListView.vue +++ b/src/frontend/components/EndpointSlice/EndpointSliceListView.vue @@ -129,8 +129,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.EndpointSlice, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.EndpointSlice, selectedNs)) }) diff --git a/src/frontend/components/HorizontalPodAutoscaler/HpaListView.vue b/src/frontend/components/HorizontalPodAutoscaler/HpaListView.vue index ad280a8b..1662baff 100644 --- a/src/frontend/components/HorizontalPodAutoscaler/HpaListView.vue +++ b/src/frontend/components/HorizontalPodAutoscaler/HpaListView.vue @@ -149,8 +149,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.HorizontalPodAutoscaler, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.HorizontalPodAutoscaler, selectedNs)) }) diff --git a/src/frontend/components/IngressClass/IngressClassListView.vue b/src/frontend/components/IngressClass/IngressClassListView.vue index e30457cc..bdd7d9fd 100644 --- a/src/frontend/components/IngressClass/IngressClassListView.vue +++ b/src/frontend/components/IngressClass/IngressClassListView.vue @@ -129,8 +129,8 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(text)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.IngressClass)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.IngressClass)) }) diff --git a/src/frontend/components/MutatingWebhook/MutatingWebhookListView.vue b/src/frontend/components/MutatingWebhook/MutatingWebhookListView.vue index 5a05065f..b8a329c3 100644 --- a/src/frontend/components/MutatingWebhook/MutatingWebhookListView.vue +++ b/src/frontend/components/MutatingWebhook/MutatingWebhookListView.vue @@ -90,8 +90,8 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(searchText.value)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.MutatingWebhookConfiguration)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.MutatingWebhookConfiguration)) }) diff --git a/src/frontend/components/NetworkPolicy/NetpolListView.vue b/src/frontend/components/NetworkPolicy/NetpolListView.vue index 37cc2712..6175acd3 100644 --- a/src/frontend/components/NetworkPolicy/NetpolListView.vue +++ b/src/frontend/components/NetworkPolicy/NetpolListView.vue @@ -137,8 +137,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.NetworkPolicy, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.NetworkPolicy, selectedNs)) }) diff --git a/src/frontend/components/PersistentVolume/PersistentVolumeListView.vue b/src/frontend/components/PersistentVolume/PersistentVolumeListView.vue index 3cf9d1c1..b02d8737 100644 --- a/src/frontend/components/PersistentVolume/PersistentVolumeListView.vue +++ b/src/frontend/components/PersistentVolume/PersistentVolumeListView.vue @@ -111,8 +111,8 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(text)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.PersistentVolume)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.PersistentVolume)) }) diff --git a/src/frontend/components/PersistentVolumeClaim/PvcListView.vue b/src/frontend/components/PersistentVolumeClaim/PvcListView.vue index 13e47958..21a3a0f4 100644 --- a/src/frontend/components/PersistentVolumeClaim/PvcListView.vue +++ b/src/frontend/components/PersistentVolumeClaim/PvcListView.vue @@ -145,8 +145,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.PersistentVolumeClaim, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.PersistentVolumeClaim, selectedNs)) }) diff --git a/src/frontend/components/PodDisruptionBudget/PdbListView.vue b/src/frontend/components/PodDisruptionBudget/PdbListView.vue index 9876936f..6189de14 100644 --- a/src/frontend/components/PodDisruptionBudget/PdbListView.vue +++ b/src/frontend/components/PodDisruptionBudget/PdbListView.vue @@ -117,8 +117,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.PodDisruptionBudget, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.PodDisruptionBudget, selectedNs)) }) diff --git a/src/frontend/components/Role/RoleListView.vue b/src/frontend/components/Role/RoleListView.vue index 4800b007..088f401c 100644 --- a/src/frontend/components/Role/RoleListView.vue +++ b/src/frontend/components/Role/RoleListView.vue @@ -117,8 +117,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Role, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Role, selectedNs)) }) diff --git a/src/frontend/components/RoleBinding/RoleBindingListView.vue b/src/frontend/components/RoleBinding/RoleBindingListView.vue index add39f4e..05995b2d 100644 --- a/src/frontend/components/RoleBinding/RoleBindingListView.vue +++ b/src/frontend/components/RoleBinding/RoleBindingListView.vue @@ -117,8 +117,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.RoleBinding, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.RoleBinding, selectedNs)) }) diff --git a/src/frontend/components/ServiceAccount/SaListView.vue b/src/frontend/components/ServiceAccount/SaListView.vue index 2855b538..b55fc23a 100644 --- a/src/frontend/components/ServiceAccount/SaListView.vue +++ b/src/frontend/components/ServiceAccount/SaListView.vue @@ -117,8 +117,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ServiceAccount, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.ServiceAccount, selectedNs)) }) diff --git a/src/frontend/components/StorageClass/StorageClassListView.vue b/src/frontend/components/StorageClass/StorageClassListView.vue index 58c588b7..6d42d43c 100644 --- a/src/frontend/components/StorageClass/StorageClassListView.vue +++ b/src/frontend/components/StorageClass/StorageClassListView.vue @@ -115,8 +115,8 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(text)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.StorageClass)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.StorageClass)) }) diff --git a/src/frontend/components/ValidatingWebhook/ValidatingWebhookListView.vue b/src/frontend/components/ValidatingWebhook/ValidatingWebhookListView.vue index a12025ae..74bdab61 100644 --- a/src/frontend/components/ValidatingWebhook/ValidatingWebhookListView.vue +++ b/src/frontend/components/ValidatingWebhook/ValidatingWebhookListView.vue @@ -90,8 +90,8 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(searchText.value)) } onMounted(() => { - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ValidatingWebhookConfiguration)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.ValidatingWebhookConfiguration)) }) diff --git a/src/frontend/components/configmap/CmListView.vue b/src/frontend/components/configmap/CmListView.vue index b0b77b08..b6e162e8 100644 --- a/src/frontend/components/configmap/CmListView.vue +++ b/src/frontend/components/configmap/CmListView.vue @@ -128,9 +128,7 @@ function onTextChanged(text: string) { onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ConfigMap, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, () => K8sService.watchService.watchChange(itemList, ResType.ConfigMap, selectedNs)) }) diff --git a/src/frontend/components/cronjob/CronJobListView.vue b/src/frontend/components/cronjob/CronJobListView.vue index d2771400..e6343574 100644 --- a/src/frontend/components/cronjob/CronJobListView.vue +++ b/src/frontend/components/cronjob/CronJobListView.vue @@ -139,12 +139,13 @@ function onTextChanged(text: string) { if (!_.isEmpty(searchText.value)) itemList.value = itemList.value.filter(r => r.metadata.name.includes(searchText.value)) } + onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.CronJob, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.CronJob, selectedNs)) }) diff --git a/src/frontend/components/daemonset/DsListView.vue b/src/frontend/components/daemonset/DsListView.vue index dbb9d81e..9858ec05 100644 --- a/src/frontend/components/daemonset/DsListView.vue +++ b/src/frontend/components/daemonset/DsListView.vue @@ -142,8 +142,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.DaemonSet, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.DaemonSet, selectedNs)) }) diff --git a/src/frontend/components/deployment/DeployListView.vue b/src/frontend/components/deployment/DeployListView.vue index 8daca4ce..54eec167 100644 --- a/src/frontend/components/deployment/DeployListView.vue +++ b/src/frontend/components/deployment/DeployListView.vue @@ -144,8 +144,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Deployment, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Deployment, selectedNs)) }) diff --git a/src/frontend/components/endpoint/EpListView.vue b/src/frontend/components/endpoint/EpListView.vue index 7114b236..22bb0165 100644 --- a/src/frontend/components/endpoint/EpListView.vue +++ b/src/frontend/components/endpoint/EpListView.vue @@ -128,9 +128,8 @@ function onTextChanged(text: string) { onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Endpoint, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Endpoint, selectedNs)) }) diff --git a/src/frontend/components/event/EventListView.vue b/src/frontend/components/event/EventListView.vue index 43b41f3c..0831d800 100644 --- a/src/frontend/components/event/EventListView.vue +++ b/src/frontend/components/event/EventListView.vue @@ -152,8 +152,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Event, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Event, selectedNs)) }) diff --git a/src/frontend/components/ingress/IngListView.vue b/src/frontend/components/ingress/IngListView.vue index e575cda4..619eadf7 100644 --- a/src/frontend/components/ingress/IngListView.vue +++ b/src/frontend/components/ingress/IngListView.vue @@ -129,8 +129,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Ingress, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Ingress, selectedNs)) }) diff --git a/src/frontend/components/job/JobListView.vue b/src/frontend/components/job/JobListView.vue index 6cd2ddcb..b011184f 100644 --- a/src/frontend/components/job/JobListView.vue +++ b/src/frontend/components/job/JobListView.vue @@ -136,8 +136,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Job, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Job, selectedNs)) }) diff --git a/src/frontend/components/limitrange/LimitsListView.vue b/src/frontend/components/limitrange/LimitsListView.vue index 72b45a83..101cc9b9 100644 --- a/src/frontend/components/limitrange/LimitsListView.vue +++ b/src/frontend/components/limitrange/LimitsListView.vue @@ -117,8 +117,8 @@ onMounted(() => { if (localStorage.selectedNs) selectedNs.value = localStorage.selectedNs - getItemList() - TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.LimitRange, selectedNs)) + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.LimitRange, selectedNs)) }) diff --git a/src/frontend/components/node/NodeListView.vue b/src/frontend/components/node/NodeListView.vue index 41d419e7..2cd8a0d3 100644 --- a/src/frontend/components/node/NodeListView.vue +++ b/src/frontend/components/node/NodeListView.vue @@ -4,7 +4,7 @@ import { DialogHelper } from '@frontend/service/page/DialogHelper' import _ from 'lodash' import type { DataTableColumns } from 'naive-ui' import { NButton, NSpace, useDialog } from 'naive-ui' -import { h, ref } from 'vue' +import { h, onMounted, ref } from 'vue' import { TimerUtils } from '@backend/utils/TimerUtils' import ResourceAgeView from '@frontend/components/common/ResourceAgeView.vue' import WorkloadListView from '@frontend/components/common/ResourceListView.vue' @@ -133,8 +133,10 @@ function onTextChanged(text: string) { itemList.value = itemList.value.filter(r => r.metadata.name.includes(text)) } -getItemList() -TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Node)) +onMounted(() => { + TimerUtils.runOnceThenDelayTwoSeconds(getItemList, + () => K8sService.watchService.watchChange(itemList, ResType.Node)) +})