@blocklet/launcher-workflow 2.4.4 → 2.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/in-progress-session.js +1 -1
- package/es/components/launch-serverless/allocate.js +181 -0
- package/es/components/launch-serverless/install.js +203 -0
- package/es/components/launch-serverless/shared/base-serverless-layout.js +53 -0
- package/es/components/launch-serverless/shared/common-components.js +605 -0
- package/es/components/launch-serverless/shared/loading-display-layout.js +122 -0
- package/es/components/launch-serverless/shared/retry-error-message.js +45 -0
- package/es/components/launch-serverless/start-app.js +356 -0
- package/es/contexts/request.js +2 -2
- package/es/hooks/use-serial-polling.js +43 -0
- package/es/install.js +28 -0
- package/es/launch.js +1 -1
- package/es/locales/en.js +71 -14
- package/es/locales/zh.js +68 -12
- package/es/paid.js +1 -1
- package/es/prepare.js +1 -1
- package/es/start-app.js +28 -0
- package/es/util.js +181 -2
- package/lib/components/in-progress-session.js +3 -3
- package/lib/components/launch-serverless/allocate.js +198 -0
- package/lib/components/launch-serverless/install.js +223 -0
- package/lib/components/launch-serverless/shared/base-serverless-layout.js +59 -0
- package/lib/components/launch-serverless/shared/common-components.js +635 -0
- package/lib/components/launch-serverless/shared/loading-display-layout.js +131 -0
- package/lib/components/launch-serverless/shared/retry-error-message.js +52 -0
- package/lib/components/launch-serverless/start-app.js +369 -0
- package/lib/contexts/request.js +2 -2
- package/lib/hooks/use-serial-polling.js +49 -0
- package/lib/install.js +35 -0
- package/lib/launch.js +2 -2
- package/lib/locales/en.js +71 -14
- package/lib/locales/zh.js +68 -12
- package/lib/paid.js +2 -2
- package/lib/prepare.js +2 -2
- package/lib/start-app.js +35 -0
- package/lib/util.js +214 -11
- package/package.json +16 -13
- package/es/components/launch-serverless.js +0 -115
- package/lib/components/launch-serverless.js +0 -89
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = LaunchServerless;
|
|
7
|
+
var _ahooks = require("ahooks");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactRouterDom = require("react-router-dom");
|
|
11
|
+
var _constant = require("@blocklet/launcher-util/lib/constant");
|
|
12
|
+
var _locale = require("../../contexts/locale");
|
|
13
|
+
var _request = _interopRequireDefault(require("../../contexts/request"));
|
|
14
|
+
var _baseServerlessLayout = _interopRequireDefault(require("./shared/base-serverless-layout"));
|
|
15
|
+
var _commonComponents = require("./shared/common-components");
|
|
16
|
+
var _loadingDisplayLayout = _interopRequireDefault(require("./shared/loading-display-layout"));
|
|
17
|
+
var _retryErrorMessage = _interopRequireDefault(require("./shared/retry-error-message"));
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
25
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
|
+
function LaunchServerless(_ref) {
|
|
27
|
+
let {
|
|
28
|
+
sessionId
|
|
29
|
+
} = _ref;
|
|
30
|
+
const {
|
|
31
|
+
t
|
|
32
|
+
} = (0, _locale.useLocaleContext)();
|
|
33
|
+
const {
|
|
34
|
+
api
|
|
35
|
+
} = (0, _request.default)();
|
|
36
|
+
const navigate = (0, _reactRouterDom.useNavigate)();
|
|
37
|
+
const timerRef = (0, _react.useRef)({});
|
|
38
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
39
|
+
allocating: true,
|
|
40
|
+
allocated: false,
|
|
41
|
+
error: '',
|
|
42
|
+
launchSession: null
|
|
43
|
+
});
|
|
44
|
+
const formatTime = (0, _commonComponents.useFormatTime)();
|
|
45
|
+
const time = (0, _commonComponents.useElapsedTime)(0);
|
|
46
|
+
const actions = (0, _react.useMemo)(() => {
|
|
47
|
+
// 基础步骤时间
|
|
48
|
+
const steps = [{
|
|
49
|
+
message: t('launch.waiting.starting'),
|
|
50
|
+
time: 1
|
|
51
|
+
}, {
|
|
52
|
+
message: t('launch.waiting.securing'),
|
|
53
|
+
time: 1
|
|
54
|
+
}, {
|
|
55
|
+
message: t('launch.waiting.prepare'),
|
|
56
|
+
time: 1
|
|
57
|
+
}, {
|
|
58
|
+
message: t('launch.waiting.waiting'),
|
|
59
|
+
time: 1
|
|
60
|
+
}, {
|
|
61
|
+
message: t('launch.waiting.done'),
|
|
62
|
+
time: 1
|
|
63
|
+
}];
|
|
64
|
+
|
|
65
|
+
// 计算总时间
|
|
66
|
+
const totalTime = steps.reduce((acc, step) => acc + step.time, 0);
|
|
67
|
+
|
|
68
|
+
// 计算每个步骤的进度区间
|
|
69
|
+
let currentProgress = 0;
|
|
70
|
+
return steps.map(step => {
|
|
71
|
+
const progressPercent = step.time / totalTime * 100;
|
|
72
|
+
const range = [Math.round(currentProgress), Math.round(currentProgress + progressPercent)];
|
|
73
|
+
currentProgress += progressPercent;
|
|
74
|
+
return _objectSpread(_objectSpread({}, step), {}, {
|
|
75
|
+
range
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}, [t]);
|
|
79
|
+
const estimatedTime = (0, _react.useMemo)(() => {
|
|
80
|
+
return actions.reduce((acc, action) => acc + action.time, 0);
|
|
81
|
+
}, [actions]);
|
|
82
|
+
const displayProgress = (0, _commonComponents.useDisplayProgress)(0, estimatedTime);
|
|
83
|
+
|
|
84
|
+
// 根据当前进度获取对应的 action
|
|
85
|
+
const getCurrentAction = progress => {
|
|
86
|
+
const action = actions.find(_ref2 => {
|
|
87
|
+
let {
|
|
88
|
+
range: [start, end]
|
|
89
|
+
} = _ref2;
|
|
90
|
+
return progress >= start && progress < end;
|
|
91
|
+
});
|
|
92
|
+
return (action === null || action === void 0 ? void 0 : action.message) || actions[actions.length - 1].message;
|
|
93
|
+
};
|
|
94
|
+
(0, _react.useEffect)(() => {
|
|
95
|
+
const fetch = async () => {
|
|
96
|
+
try {
|
|
97
|
+
const {
|
|
98
|
+
data: {
|
|
99
|
+
launch: launchSession
|
|
100
|
+
}
|
|
101
|
+
} = await api.get("/launches/".concat(sessionId, "?health=1"));
|
|
102
|
+
setState({
|
|
103
|
+
launchSession
|
|
104
|
+
});
|
|
105
|
+
if (launchSession.status >= _constant.LAUNCH_STATUS.installed) {
|
|
106
|
+
navigate("/start-app/".concat(sessionId).concat(window.location.search || ''));
|
|
107
|
+
} else if (launchSession.status >= _constant.LAUNCH_STATUS.allocated) {
|
|
108
|
+
navigate("/install/".concat(sessionId).concat(window.location.search || ''));
|
|
109
|
+
} else {
|
|
110
|
+
await Promise.all([api.post('/serverless/allocate', {
|
|
111
|
+
launchId: sessionId
|
|
112
|
+
}), new Promise(resolve => {
|
|
113
|
+
timerRef.current.raceTimer = setTimeout(() => {
|
|
114
|
+
resolve();
|
|
115
|
+
}, estimatedTime * 1000);
|
|
116
|
+
})]);
|
|
117
|
+
setState({
|
|
118
|
+
allocating: false,
|
|
119
|
+
allocated: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
setState({
|
|
124
|
+
error: error.message,
|
|
125
|
+
allocating: false
|
|
126
|
+
});
|
|
127
|
+
console.error(error);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
if (window.blocklet.DEVELOPER_WORKFLOW_UI) {
|
|
131
|
+
timerRef.current.mockTimer = setTimeout(() => {
|
|
132
|
+
navigate("/install/".concat(sessionId).concat(window.location.search || ''));
|
|
133
|
+
}, 5000);
|
|
134
|
+
} else {
|
|
135
|
+
fetch();
|
|
136
|
+
}
|
|
137
|
+
return () => {
|
|
138
|
+
const timers = Object.values(timerRef.current); // eslint-disable-line react-hooks/exhaustive-deps
|
|
139
|
+
timers.forEach(timer => clearTimeout(timer));
|
|
140
|
+
};
|
|
141
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
142
|
+
}, []);
|
|
143
|
+
(0, _react.useEffect)(() => {
|
|
144
|
+
if (state.allocated) {
|
|
145
|
+
const timer = setTimeout(() => {
|
|
146
|
+
navigate("/install/".concat(sessionId).concat(window.location.search || ''));
|
|
147
|
+
}, 1000);
|
|
148
|
+
return () => clearTimeout(timer);
|
|
149
|
+
}
|
|
150
|
+
return () => {};
|
|
151
|
+
}, [state.allocated, sessionId, navigate]);
|
|
152
|
+
const handleRetry = async () => {
|
|
153
|
+
try {
|
|
154
|
+
var _state$launchSession;
|
|
155
|
+
setState({
|
|
156
|
+
error: '',
|
|
157
|
+
allocating: true
|
|
158
|
+
});
|
|
159
|
+
if (!((_state$launchSession = state.launchSession) !== null && _state$launchSession !== void 0 && _state$launchSession.status) || state.launchSession.status < _constant.LAUNCH_STATUS.allocated) {
|
|
160
|
+
await api.post('/serverless/allocate', {
|
|
161
|
+
launchId: sessionId
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
164
|
+
await api.post('/serverless/install', {
|
|
165
|
+
launchId: sessionId
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
setState({
|
|
169
|
+
allocating: false,
|
|
170
|
+
allocated: true
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
setState({
|
|
174
|
+
error: error.message,
|
|
175
|
+
allocating: false
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_baseServerlessLayout.default, {
|
|
180
|
+
title: t('launch.pageTitle'),
|
|
181
|
+
children: [!state.error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_loadingDisplayLayout.default, {
|
|
182
|
+
title: t('launch.pageTitle'),
|
|
183
|
+
progress: state.allocated ? 100 : Math.max(0, Math.min(displayProgress, 100)),
|
|
184
|
+
elapsedTime: formatTime(time),
|
|
185
|
+
estimatedTime: formatTime(estimatedTime),
|
|
186
|
+
currentAction: getCurrentAction(displayProgress),
|
|
187
|
+
error: null,
|
|
188
|
+
onRetry: null
|
|
189
|
+
}), state.error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_retryErrorMessage.default, {
|
|
190
|
+
title: t('prepare.serverless.prepareFailed'),
|
|
191
|
+
onRetry: handleRetry,
|
|
192
|
+
retryText: t('common.retry')
|
|
193
|
+
})]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
LaunchServerless.propTypes = {
|
|
197
|
+
sessionId: _propTypes.default.string.isRequired
|
|
198
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = LaunchServerless;
|
|
7
|
+
var _ahooks = require("ahooks");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactRouterDom = require("react-router-dom");
|
|
11
|
+
var _locale = require("../../contexts/locale");
|
|
12
|
+
var _request = _interopRequireDefault(require("../../contexts/request"));
|
|
13
|
+
var _useSerialPolling = _interopRequireDefault(require("../../hooks/use-serial-polling"));
|
|
14
|
+
var _baseServerlessLayout = _interopRequireDefault(require("./shared/base-serverless-layout"));
|
|
15
|
+
var _commonComponents = require("./shared/common-components");
|
|
16
|
+
var _loadingDisplayLayout = _interopRequireDefault(require("./shared/loading-display-layout"));
|
|
17
|
+
var _retryErrorMessage = _interopRequireDefault(require("./shared/retry-error-message"));
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
25
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
|
+
const CHECK_INTERVAL = 2000;
|
|
27
|
+
const STATUS = {
|
|
28
|
+
installing: 1,
|
|
29
|
+
installed: 2,
|
|
30
|
+
error: 10
|
|
31
|
+
};
|
|
32
|
+
function LaunchServerless(_ref) {
|
|
33
|
+
let {
|
|
34
|
+
sessionId
|
|
35
|
+
} = _ref;
|
|
36
|
+
const {
|
|
37
|
+
t
|
|
38
|
+
} = (0, _locale.useLocaleContext)();
|
|
39
|
+
const {
|
|
40
|
+
api
|
|
41
|
+
} = (0, _request.default)();
|
|
42
|
+
const navigate = (0, _reactRouterDom.useNavigate)();
|
|
43
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
44
|
+
status: STATUS.installing,
|
|
45
|
+
startTime: Date.now(),
|
|
46
|
+
hasTryInstall: false,
|
|
47
|
+
retryCount: 0,
|
|
48
|
+
error: ''
|
|
49
|
+
});
|
|
50
|
+
const formatTime = (0, _commonComponents.useFormatTime)();
|
|
51
|
+
|
|
52
|
+
// 定义带进度区间的 actions
|
|
53
|
+
const actions = (0, _react.useMemo)(() => {
|
|
54
|
+
// 基础步骤时间
|
|
55
|
+
const steps = [{
|
|
56
|
+
message: t('install.waiting.verifying'),
|
|
57
|
+
time: 2
|
|
58
|
+
}, {
|
|
59
|
+
message: t('install.waiting.downloading'),
|
|
60
|
+
time: 5
|
|
61
|
+
}, {
|
|
62
|
+
message: t('install.waiting.extracting'),
|
|
63
|
+
time: 2
|
|
64
|
+
}, {
|
|
65
|
+
message: t('install.waiting.installing'),
|
|
66
|
+
time: 3
|
|
67
|
+
}, {
|
|
68
|
+
message: t('install.waiting.installed'),
|
|
69
|
+
time: 1
|
|
70
|
+
}];
|
|
71
|
+
|
|
72
|
+
// 计算总时间
|
|
73
|
+
const totalTime = steps.reduce((acc, step) => acc + step.time, 0);
|
|
74
|
+
|
|
75
|
+
// 计算每个步骤的进度区间
|
|
76
|
+
let currentProgress = 0;
|
|
77
|
+
return steps.map(step => {
|
|
78
|
+
const progressPercent = step.time / totalTime * 100;
|
|
79
|
+
const range = [Math.round(currentProgress), Math.round(currentProgress + progressPercent)];
|
|
80
|
+
currentProgress += progressPercent;
|
|
81
|
+
return _objectSpread(_objectSpread({}, step), {}, {
|
|
82
|
+
range
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}, [t]);
|
|
86
|
+
|
|
87
|
+
// 根据组件计算预估时间
|
|
88
|
+
const estimatedTime = (0, _react.useMemo)(() => {
|
|
89
|
+
var _window$blockletMeta;
|
|
90
|
+
const components = ((_window$blockletMeta = window.blockletMeta) === null || _window$blockletMeta === void 0 ? void 0 : _window$blockletMeta.components) || [];
|
|
91
|
+
const additionalTime = (0, _commonComponents.calculateEstimatedTime)(components);
|
|
92
|
+
return actions.reduce((acc, _ref2) => {
|
|
93
|
+
let {
|
|
94
|
+
time
|
|
95
|
+
} = _ref2;
|
|
96
|
+
return acc + time;
|
|
97
|
+
}, 0) + Math.ceil(additionalTime * 0.6);
|
|
98
|
+
}, [actions]);
|
|
99
|
+
|
|
100
|
+
// 根据当前进度获取对应的 action
|
|
101
|
+
const getCurrentAction = progress => {
|
|
102
|
+
const action = actions.find(_ref3 => {
|
|
103
|
+
let {
|
|
104
|
+
range: [start, end]
|
|
105
|
+
} = _ref3;
|
|
106
|
+
return progress >= start && progress < end;
|
|
107
|
+
});
|
|
108
|
+
return (action === null || action === void 0 ? void 0 : action.message) || actions[actions.length - 1].message;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// 时间管理 - 参考 launch-dedicated.js
|
|
112
|
+
let installStartTime = sessionStorage.getItem("launcher-install-".concat(sessionId, "-time"));
|
|
113
|
+
if (!installStartTime) {
|
|
114
|
+
installStartTime = Date.now();
|
|
115
|
+
sessionStorage.setItem("launcher-install-".concat(sessionId, "-time"), installStartTime);
|
|
116
|
+
}
|
|
117
|
+
const time = (0, _commonComponents.useElapsedTime)(Math.round((Date.now() - installStartTime) / 1000));
|
|
118
|
+
const startProgress = (0, _react.useMemo)(() => {
|
|
119
|
+
return Math.min(time / estimatedTime * 100, 90);
|
|
120
|
+
}, [time, estimatedTime]);
|
|
121
|
+
const displayProgress = (0, _commonComponents.useDisplayProgress)(startProgress, state.status === STATUS.installed ? Math.min(estimatedTime - time, 2) : estimatedTime);
|
|
122
|
+
const checkLaunchSession = async () => {
|
|
123
|
+
if (window.blocklet.DEVELOPER_WORKFLOW_UI) {
|
|
124
|
+
// 开发模式下的模拟逻辑
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
setState({
|
|
127
|
+
status: STATUS.installed
|
|
128
|
+
});
|
|
129
|
+
sessionStorage.removeItem("launcher-install-".concat(sessionId, "-time"));
|
|
130
|
+
navigate("/start-app/".concat(sessionId).concat(window.location.search || ''));
|
|
131
|
+
}, 47000);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const {
|
|
136
|
+
data: {
|
|
137
|
+
launch: launchSession
|
|
138
|
+
}
|
|
139
|
+
} = await api.get("/launches/".concat(sessionId, "?health=1"));
|
|
140
|
+
const {
|
|
141
|
+
status
|
|
142
|
+
} = launchSession.metadata;
|
|
143
|
+
const hasInstalled = ['starting', 'installed', 'running', 'stopped'].includes(status);
|
|
144
|
+
if (launchSession.running || hasInstalled) {
|
|
145
|
+
sessionStorage.removeItem("launcher-install-".concat(sessionId, "-time"));
|
|
146
|
+
setState({
|
|
147
|
+
status: STATUS.installed
|
|
148
|
+
});
|
|
149
|
+
if (['installed', 'stopped'].includes(status)) {
|
|
150
|
+
await api.post("/launches/".concat(sessionId, "/start")).catch(error => {
|
|
151
|
+
console.error(error);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
} else if (!state.hasTryInstall && !hasInstalled && Date.now() - state.startTime > 20000) {
|
|
155
|
+
setState({
|
|
156
|
+
hasTryInstall: true
|
|
157
|
+
});
|
|
158
|
+
await api.post('/serverless/install', {
|
|
159
|
+
launchId: sessionId
|
|
160
|
+
}).catch(error => {
|
|
161
|
+
console.error(error);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
setState({
|
|
165
|
+
retryCount: 0
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (state.retryCount < 5) {
|
|
169
|
+
console.warn('check launch session occurred error, retry', state.retryCount, error);
|
|
170
|
+
setState({
|
|
171
|
+
retryCount: state.retryCount + 1
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
sessionStorage.removeItem("launcher-install-".concat(sessionId, "-time"));
|
|
175
|
+
setState({
|
|
176
|
+
error: error.message,
|
|
177
|
+
status: STATUS.error,
|
|
178
|
+
retryCount: 0
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// 串行检查安装状态
|
|
185
|
+
(0, _useSerialPolling.default)({
|
|
186
|
+
isEnabled: state.status === STATUS.installing,
|
|
187
|
+
interval: CHECK_INTERVAL,
|
|
188
|
+
onPoll: checkLaunchSession
|
|
189
|
+
});
|
|
190
|
+
(0, _react.useEffect)(() => {
|
|
191
|
+
if (state.status === STATUS.installed && displayProgress >= 99) {
|
|
192
|
+
const timer = setTimeout(() => {
|
|
193
|
+
sessionStorage.removeItem("launcher-install-".concat(sessionId, "-time"));
|
|
194
|
+
navigate("/start-app/".concat(sessionId).concat(window.location.search || ''));
|
|
195
|
+
}, 1500);
|
|
196
|
+
return () => clearTimeout(timer);
|
|
197
|
+
}
|
|
198
|
+
return () => {};
|
|
199
|
+
}, [state.status, sessionId, navigate, displayProgress]);
|
|
200
|
+
const handleRetry = () => {
|
|
201
|
+
sessionStorage.removeItem("launcher-install-".concat(sessionId, "-time"));
|
|
202
|
+
navigate("/launch/".concat(sessionId).concat(window.location.search || ''));
|
|
203
|
+
};
|
|
204
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_baseServerlessLayout.default, {
|
|
205
|
+
title: t('install.pageTitle'),
|
|
206
|
+
children: [state.status !== STATUS.error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_loadingDisplayLayout.default, {
|
|
207
|
+
title: t('install.pageTitle'),
|
|
208
|
+
progress: state.status === STATUS.installed && displayProgress >= 99 ? 100 : displayProgress,
|
|
209
|
+
elapsedTime: formatTime(time),
|
|
210
|
+
estimatedTime: formatTime(estimatedTime),
|
|
211
|
+
currentAction: getCurrentAction(displayProgress),
|
|
212
|
+
error: null,
|
|
213
|
+
onRetry: handleRetry
|
|
214
|
+
}), state.status === STATUS.error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_retryErrorMessage.default, {
|
|
215
|
+
title: t('install.installFailed'),
|
|
216
|
+
onRetry: handleRetry,
|
|
217
|
+
retryText: t('common.retry')
|
|
218
|
+
})]
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
LaunchServerless.propTypes = {
|
|
222
|
+
sessionId: _propTypes.default.string.isRequired
|
|
223
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = BaseServerlessLayout;
|
|
7
|
+
var _material = require("@mui/material");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
/**
|
|
13
|
+
* 无服务器启动流程的基础布局组件
|
|
14
|
+
* 提取公共的样式和结构,避免重复代码
|
|
15
|
+
*/function BaseServerlessLayout(_ref) {
|
|
16
|
+
let {
|
|
17
|
+
title,
|
|
18
|
+
children
|
|
19
|
+
} = _ref;
|
|
20
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
21
|
+
sx: {
|
|
22
|
+
display: 'flex',
|
|
23
|
+
flexDirection: 'column',
|
|
24
|
+
width: '100%',
|
|
25
|
+
height: '100%',
|
|
26
|
+
paddingTop: '100px',
|
|
27
|
+
'& .page-logo': {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
justifyContent: 'center',
|
|
30
|
+
marginTop: {
|
|
31
|
+
xs: '48px',
|
|
32
|
+
md: '62px'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
37
|
+
sx: {
|
|
38
|
+
display: 'flex',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
flexDirection: 'column',
|
|
41
|
+
textAlign: 'center',
|
|
42
|
+
'& .loading-description': {
|
|
43
|
+
marginTop: '8px'
|
|
44
|
+
},
|
|
45
|
+
'& .result-title': {
|
|
46
|
+
fontSize: '18px'
|
|
47
|
+
},
|
|
48
|
+
'& .result-title.color-loading': {
|
|
49
|
+
color: 'primary.main'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
children: children
|
|
53
|
+
})
|
|
54
|
+
}, title);
|
|
55
|
+
}
|
|
56
|
+
BaseServerlessLayout.propTypes = {
|
|
57
|
+
title: _propTypes.default.string.isRequired,
|
|
58
|
+
children: _propTypes.default.node.isRequired
|
|
59
|
+
};
|