wait until restart is complete

This commit is contained in:
Sebastian Sdorra
2019-08-22 08:24:01 +02:00
parent 6351e39c12
commit b796e45fb4
4 changed files with 79 additions and 19 deletions

View File

@@ -10,6 +10,8 @@ import {
} from "@scm-manager/ui-components";
import type { PluginCollection } from "@scm-manager/ui-types";
import { translate } from "react-i18next";
import waitForRestart from "./waitForRestart";
import InstallSuccessNotification from "./InstallSuccessNotification";
type Props = {
onClose: () => void,
@@ -40,14 +42,7 @@ class InstallPendingModal extends React.Component<Props, State> {
if (error) {
return <ErrorNotification error={error} />;
} else if (success) {
return (
<Notification type="success">
{t("plugins.modal.successNotification")}{" "}
<a onClick={e => window.location.reload()}>
{t("plugins.modal.reload")}
</a>
</Notification>
);
return <InstallSuccessNotification />;
} else {
return (
<Notification type="warning">
@@ -65,6 +60,7 @@ class InstallPendingModal extends React.Component<Props, State> {
apiClient
.post(collection._links.installPending.href)
.then(waitForRestart)
.then(() => {
this.setState({
success: true,
@@ -92,7 +88,9 @@ class InstallPendingModal extends React.Component<Props, State> {
{collection._embedded.plugins
.filter(plugin => plugin.pending)
.map(plugin => (
<li key={plugin.name} className="has-text-weight-bold">{plugin.name}</li>
<li key={plugin.name} className="has-text-weight-bold">
{plugin.name}
</li>
))}
</ul>
</div>

View File

@@ -0,0 +1,25 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { Notification } from "@scm-manager/ui-components";
type Props = {
// context props
t: string => string
};
class InstallSuccessNotification extends React.Component<Props> {
render() {
const { t } = this.props;
return (
<Notification type="success">
{t("plugins.modal.successNotification")}{" "}
<a onClick={e => window.location.reload(true)}>
{t("plugins.modal.reload")}
</a>
</Notification>
);
}
}
export default translate("admin")(InstallSuccessNotification);

View File

@@ -14,6 +14,8 @@ import {
Notification
} from "@scm-manager/ui-components";
import classNames from "classnames";
import waitForRestart from "./waitForRestart";
import InstallSuccessNotification from "./InstallSuccessNotification";
type Props = {
plugin: Plugin,
@@ -63,10 +65,20 @@ class PluginModal extends React.Component<Props, State> {
};
if (restart) {
this.setState({
...newState,
success: true
});
waitForRestart()
.then(() => {
this.setState({
...newState,
success: true
});
})
.catch(error => {
this.setState({
loading: false,
success: false,
error
});
});
} else {
this.setState(newState, () => {
refresh();
@@ -150,12 +162,7 @@ class PluginModal extends React.Component<Props, State> {
} else if (success) {
return (
<div className="media">
<Notification type="success">
{t("plugins.modal.successNotification")}{" "}
<a onClick={e => window.location.reload()}>
{t("plugins.modal.reload")}
</a>
</Notification>
<InstallSuccessNotification />
</div>
);
} else if (restart) {

View File

@@ -0,0 +1,30 @@
// @flow
import { apiClient } from "@scm-manager/ui-components";
const waitForRestart = () => {
const endTime = Number(new Date()) + 10000;
let started = false;
const executor = (resolve, reject) => {
// we need some initial delay
if (!started) {
started = true;
setTimeout(executor, 100, resolve, reject);
} else {
apiClient
.get("")
.then(resolve)
.catch(() => {
if (Number(new Date()) < endTime) {
setTimeout(executor, 500, resolve, reject);
} else {
reject(new Error("timeout reached"));
}
});
}
};
return new Promise<void>(executor);
};
export default waitForRestart;