Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add supports for check started status after start plugin operation #4558

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions console/src/modules/system/plugins/composables/use-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ 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,
});

await checkStatus(newPlugin);

return newPlugin;
},
retry: 3,
retryDelay: 1000,
Expand All @@ -61,6 +67,38 @@ export function usePluginLifeCycle(
},
});

function checkStatus(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) => {
const { enabled } = response.data.spec;
const { phase } = response.data.status || {};
if (
(enabled && phase === "STARTED") ||
(!enabled && phase !== "STARTED")
) {
resolve(true);
} else {
setTimeout(check, 1000);
retryCount++;
}
})
.catch(() => {
reject(false);
});
};
check();
});
}

const uninstall = (deleteExtensions?: boolean) => {
if (!plugin?.value) return;

Expand Down