From 7a8255f85bd0c170e8901cb38e8774c5b52cec24 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 6 Sep 2023 18:04:09 +0800 Subject: [PATCH 1/2] feat: add supports for check started status after start plugin operation Signed-off-by: Ryan Wang --- .../system/plugins/composables/use-plugin.ts | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/console/src/modules/system/plugins/composables/use-plugin.ts b/console/src/modules/system/plugins/composables/use-plugin.ts index cc4e46549d..744e6452a5 100644 --- a/console/src/modules/system/plugins/composables/use-plugin.ts +++ b/console/src/modules/system/plugins/composables/use-plugin.ts @@ -49,10 +49,18 @@ export function usePluginLifeCycle( }); pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; - await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({ - name: pluginToUpdate.metadata.name, - plugin: pluginToUpdate, - }); + + const { data: newPlugin } = + await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({ + name: pluginToUpdate.metadata.name, + plugin: pluginToUpdate, + }); + + if (newPlugin.spec.enabled) { + await checkStartedStatus(newPlugin); + } + + return newPlugin; }, retry: 3, retryDelay: 1000, @@ -61,6 +69,33 @@ export function usePluginLifeCycle( }, }); + function checkStartedStatus(plugin: Plugin) { + const maxRetry = 5; + let retryCount = 0; + return new Promise((resolve, reject) => { + const check = () => { + if (retryCount >= maxRetry) { + reject(false); + return; + } + apiClient.extension.plugin + .getpluginHaloRunV1alpha1Plugin({ name: plugin.metadata.name }) + .then((response) => { + if (response.data.status?.phase === "STARTED") { + resolve(true); + } else { + setTimeout(check, 1000); + retryCount++; + } + }) + .catch(() => { + reject(false); + }); + }; + check(); + }); + } + const uninstall = (deleteExtensions?: boolean) => { if (!plugin?.value) return; From 532646b1459689e8c25a9119692131d2888005fd Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 7 Sep 2023 10:39:30 +0800 Subject: [PATCH 2/2] Refine checkStatus function Signed-off-by: Ryan Wang --- .../system/plugins/composables/use-plugin.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/console/src/modules/system/plugins/composables/use-plugin.ts b/console/src/modules/system/plugins/composables/use-plugin.ts index 744e6452a5..9408e7247e 100644 --- a/console/src/modules/system/plugins/composables/use-plugin.ts +++ b/console/src/modules/system/plugins/composables/use-plugin.ts @@ -56,9 +56,7 @@ export function usePluginLifeCycle( plugin: pluginToUpdate, }); - if (newPlugin.spec.enabled) { - await checkStartedStatus(newPlugin); - } + await checkStatus(newPlugin); return newPlugin; }, @@ -69,7 +67,7 @@ export function usePluginLifeCycle( }, }); - function checkStartedStatus(plugin: Plugin) { + function checkStatus(plugin: Plugin) { const maxRetry = 5; let retryCount = 0; return new Promise((resolve, reject) => { @@ -81,7 +79,12 @@ export function usePluginLifeCycle( apiClient.extension.plugin .getpluginHaloRunV1alpha1Plugin({ name: plugin.metadata.name }) .then((response) => { - if (response.data.status?.phase === "STARTED") { + const { enabled } = response.data.spec; + const { phase } = response.data.status || {}; + if ( + (enabled && phase === "STARTED") || + (!enabled && phase !== "STARTED") + ) { resolve(true); } else { setTimeout(check, 1000);