Skip to content

Commit

Permalink
feat: add supports for check started status after start plugin operat…
Browse files Browse the repository at this point in the history
…ion (#4558)

#### What type of PR is this?

/area console
/kind improvement
/milestone 2.10.x

#### What this PR does / why we need it:

支持在启动插件之后检测插件的启动状态,防止直接刷新之后 bundle.js 的内容没有及时更新。

#### Does this PR introduce a user-facing change?

```release-note
优化 Console 端启动插件的逻辑
```
  • Loading branch information
ruibaby authored Sep 7, 2023
1 parent 2baf6ae commit a1ea355
Showing 1 changed file with 42 additions and 4 deletions.
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

0 comments on commit a1ea355

Please sign in to comment.