Skip to content

Commit

Permalink
feat: add supports for check started status after start plugin operation
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 6, 2023
1 parent 2baf6ae commit 7a8255f
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 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,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,
Expand All @@ -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;

Expand Down

0 comments on commit 7a8255f

Please sign in to comment.