Skip to content

Commit

Permalink
Refine checkStatus function
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <i@ryanc.cc>
  • Loading branch information
ruibaby committed Sep 7, 2023
1 parent 7a8255f commit 532646b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions console/src/modules/system/plugins/composables/use-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export function usePluginLifeCycle(
plugin: pluginToUpdate,
});

if (newPlugin.spec.enabled) {
await checkStartedStatus(newPlugin);
}
await checkStatus(newPlugin);

return newPlugin;
},
Expand All @@ -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) => {
Expand All @@ -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);
Expand Down

0 comments on commit 532646b

Please sign in to comment.