@kne/fastify-app-manager 0.1.13 → 0.1.14

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.
@@ -241,7 +241,7 @@ module.exports = fp(async (fastify, options) => {
241
241
  order: [['createdAt', 'DESC']]
242
242
  });
243
243
  return {
244
- pageData: rows.map(toPublicApp),
244
+ pageData: rows.map(row => Object.assign(toPublicApp(row), { deployment: deployProgress.active(row.name) })),
245
245
  totalCount: count
246
246
  };
247
247
  };
@@ -265,7 +265,7 @@ module.exports = fp(async (fastify, options) => {
265
265
 
266
266
  const detail = async ({ name }) => {
267
267
  const app = await getByName(name);
268
- return toPublicApp(app);
268
+ return Object.assign(toPublicApp(app), { deployment: deployProgress.active(app.name) });
269
269
  };
270
270
 
271
271
  const versionSqlDir = ver => path.join(ver.artifactPath, 'server', ver.migrationPath || options.sqlPath || 'sql');
@@ -938,7 +938,7 @@ module.exports = fp(async (fastify, options) => {
938
938
  httpError(404, 'version not found');
939
939
  }
940
940
 
941
- const progress = deployProgress.begin(app.name, progressId || crypto.randomUUID());
941
+ const progress = deployProgress.begin(app.name, progressId || crypto.randomUUID(), { versionId: String(ver.id), version: ver.version });
942
942
  let step = 'package';
943
943
  progress.report(step, 'running');
944
944
  try {
@@ -12,8 +12,8 @@ const createDeployProgress = () => {
12
12
  emitter.setMaxListeners(0);
13
13
  const latest = new Map();
14
14
 
15
- const begin = (name, progressId) => {
16
- const state = { progressId, events: [] };
15
+ const begin = (name, progressId, { versionId = null, version = null } = {}) => {
16
+ const state = { progressId, versionId, version, startedAt: new Date().toISOString(), events: [] };
17
17
  latest.set(name, state);
18
18
  const report = (step, status, { detail = null, message = null } = {}) => {
19
19
  const event = { progressId, step, status, detail, message, at: new Date().toISOString() };
@@ -30,6 +30,23 @@ const createDeployProgress = () => {
30
30
 
31
31
  const isFinished = event => event.status === 'error' || (event.step === 'ready' && event.status !== 'running');
32
32
 
33
+ /** 尚未结束的最近一次部署;准备部署包阶段应用仍是旧状态与旧版本,需靠它判断哪个版本正在部署 */
34
+ const active = name => {
35
+ const state = latest.get(name);
36
+ if (!state || state.events.some(isFinished)) {
37
+ return null;
38
+ }
39
+ const last = state.events[state.events.length - 1];
40
+ return {
41
+ progressId: state.progressId,
42
+ versionId: state.versionId,
43
+ version: state.version,
44
+ startedAt: state.startedAt,
45
+ step: last ? last.step : null,
46
+ detail: last ? last.detail : null
47
+ };
48
+ };
49
+
33
50
  /** 等到该次部署出错或就绪阶段结束(或超时);返回 { progressId, ok, timedOut, events } */
34
51
  const wait = (name, progressId, { timeoutMs = 120000 } = {}) =>
35
52
  new Promise(resolve => {
@@ -57,7 +74,7 @@ const createDeployProgress = () => {
57
74
  timer = setTimeout(() => finish(true), timeoutMs);
58
75
  });
59
76
 
60
- return { emitter, begin, snapshot, clear, wait };
77
+ return { emitter, begin, snapshot, active, clear, wait };
61
78
  };
62
79
 
63
80
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-app-manager",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Fastify 单机应用市场插件:版本上传、PM2 托管、路径/域名反代与日志 SSE",
5
5
  "main": "index.js",
6
6
  "scripts": {