Skip to content

Commit

Permalink
TimerUtils update
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed Nov 12, 2023
1 parent 793920e commit baa11ae
Show file tree
Hide file tree
Showing 34 changed files with 77 additions and 70 deletions.
5 changes: 5 additions & 0 deletions src/backend/utils/TimerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/components/ClusterRole/ClusterRoleListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/IngressClass/IngressClassListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/NetworkPolicy/NetpolListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/PersistentVolumeClaim/PvcListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/PodDisruptionBudget/PdbListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/Role/RoleListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/RoleBinding/RoleBindingListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/ServiceAccount/SaListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/StorageClass/StorageClassListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 1 addition & 3 deletions src/frontend/components/configmap/CmListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
5 changes: 3 additions & 2 deletions src/frontend/components/cronjob/CronJobListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/daemonset/DsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/deployment/DeployListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
5 changes: 2 additions & 3 deletions src/frontend/components/endpoint/EpListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/event/EventListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/ingress/IngListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/job/JobListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/limitrange/LimitsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
</script>

Expand Down
8 changes: 5 additions & 3 deletions src/frontend/components/node/NodeListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))
})
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/ns/NsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,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.Namespace))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList,
() => K8sService.watchService.watchChange(itemList, ResType.Namespace))
})
</script>

Expand Down
5 changes: 3 additions & 2 deletions src/frontend/components/pod/PodListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const dialog = useDialog()
const itemList = ref<V1Pod[]>()
const selectedNs = ref('default')
const workloadListViewRef = ref<InstanceType<typeof WorkloadListView>>()
function createColumns(): DataTableColumns<V1Pod> {
return [
{
Expand Down Expand Up @@ -209,6 +210,7 @@ function onNsChanged(ns: string) {
selectedNs.value = ns
getItemList()
}
function onTextChanged(text: string) {
if (_.isEmpty(text)) {
getItemList()
Expand All @@ -221,8 +223,7 @@ onMounted(() => {
if (localStorage.selectedNs)
selectedNs.value = localStorage.selectedNs
getItemList()
TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Pod, selectedNs))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList, () => K8sService.watchService.watchChange(itemList, ResType.Pod, selectedNs))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/priorityclass/PcListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,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.PriorityClass))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList,
() => K8sService.watchService.watchChange(itemList, ResType.PriorityClass))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/replicacontroller/RcListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ onMounted(() => {
if (localStorage.selectedNs)
selectedNs.value = localStorage.selectedNs
getItemList()
TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ReplicationController, selectedNs))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList,
() => K8sService.watchService.watchChange(itemList, ResType.ReplicationController, selectedNs))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/resourcequota/QuotaListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ onMounted(() => {
if (localStorage.selectedNs)
selectedNs.value = localStorage.selectedNs
getItemList()
TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.ResourceQuota, selectedNs))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList,
() => K8sService.watchService.watchChange(itemList, ResType.ResourceQuota, selectedNs))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/secret/SecretListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ onMounted(() => {
if (localStorage.selectedNs)
selectedNs.value = localStorage.selectedNs
getItemList()
TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Secret, selectedNs))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList,
() => K8sService.watchService.watchChange(itemList, ResType.Secret, selectedNs))
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/service/SvcListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ onMounted(() => {
if (localStorage.selectedNs)
selectedNs.value = localStorage.selectedNs
getItemList()
TimerUtils.delayTwoSeconds(() => K8sService.watchService.watchChange(itemList, ResType.Service, selectedNs))
TimerUtils.runOnceThenDelayTwoSeconds(getItemList,
() => K8sService.watchService.watchChange(itemList, ResType.Service, selectedNs))
})
</script>

Expand Down
Loading

0 comments on commit baa11ae

Please sign in to comment.