@abtnode/core 1.16.29-beta-8671c2cf → 1.16.29-beta-1fb308f8
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.
|
@@ -2,6 +2,7 @@ const path = require('path');
|
|
|
2
2
|
const { PROJECT } = require('@blocklet/constant');
|
|
3
3
|
const { upload } = require('@blocklet/store');
|
|
4
4
|
const { getDisplayName } = require('@blocklet/meta/lib/util');
|
|
5
|
+
const fs = require('fs/promises');
|
|
5
6
|
|
|
6
7
|
function ensureArray(value) {
|
|
7
8
|
if (!value) {
|
|
@@ -18,6 +19,37 @@ function getReleaseDir(blocklet, projectId, releaseId) {
|
|
|
18
19
|
return path.join(projectDir, PROJECT.RELEASE_DIR, `${releaseId}`);
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
const MAX_RETRIES = 5;
|
|
23
|
+
const RETRY_DELAY = 100;
|
|
24
|
+
|
|
25
|
+
// 利用乐观锁, 去更新字段, 如果连续5次都失败, 就算更新失败
|
|
26
|
+
async function updateReleaseWithRetry(releaseState, releaseId, projectId, storeId) {
|
|
27
|
+
// eslint-disable-next-line no-unused-vars
|
|
28
|
+
for (const _ of Array(MAX_RETRIES).fill(0)) {
|
|
29
|
+
// eslint-disable-next-line no-await-in-loop
|
|
30
|
+
const release = await releaseState.findOne({ projectId, id: releaseId });
|
|
31
|
+
release.publishedStoreIds = ensureArray(release.publishedStoreIds);
|
|
32
|
+
release.publishedStoreIds.push(storeId);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
// eslint-disable-next-line no-await-in-loop
|
|
36
|
+
const result = await releaseState.update(
|
|
37
|
+
{ id: releaseId, updatedAt: release.updatedAt },
|
|
38
|
+
{ $set: { publishedStoreIds: Array.from(new Set(release.publishedStoreIds)) } }
|
|
39
|
+
);
|
|
40
|
+
if (result?.[0] > 0) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line no-await-in-loop
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error(`Failed to update release: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error('Failed to update release after maximum retries');
|
|
51
|
+
}
|
|
52
|
+
|
|
21
53
|
const publishToStore = async ({ did, projectId, releaseId, type, storeId, manager }) => {
|
|
22
54
|
if (
|
|
23
55
|
!did ||
|
|
@@ -42,6 +74,7 @@ const publishToStore = async ({ did, projectId, releaseId, type, storeId, manage
|
|
|
42
74
|
if (!store) {
|
|
43
75
|
throw new Error('no find connected store');
|
|
44
76
|
}
|
|
77
|
+
|
|
45
78
|
const { storeUrl } = store;
|
|
46
79
|
const { accessToken, developerDid } = store;
|
|
47
80
|
|
|
@@ -50,7 +83,12 @@ const publishToStore = async ({ did, projectId, releaseId, type, storeId, manage
|
|
|
50
83
|
throw new Error('blocklet not found');
|
|
51
84
|
}
|
|
52
85
|
|
|
53
|
-
const
|
|
86
|
+
const project = await projectState.findOne({ id: projectId });
|
|
87
|
+
let releaseDir = getReleaseDir(blocklet, projectId, releaseId);
|
|
88
|
+
if (project.possibleSameStore) {
|
|
89
|
+
await fs.cp(releaseDir, `${releaseDir}-${storeId}`, { recursive: true });
|
|
90
|
+
releaseDir = `${releaseDir}-${storeId}`;
|
|
91
|
+
}
|
|
54
92
|
const metaFile = path.join(releaseDir, '.blocklet', 'release', 'blocklet.json');
|
|
55
93
|
|
|
56
94
|
const response = await upload({
|
|
@@ -58,16 +96,11 @@ const publishToStore = async ({ did, projectId, releaseId, type, storeId, manage
|
|
|
58
96
|
storeUrl,
|
|
59
97
|
accessToken,
|
|
60
98
|
developerDid,
|
|
99
|
+
possibleSameStore: project.possibleSameStore,
|
|
61
100
|
source: `Blocklet Studio (${getDisplayName(blocklet)})`,
|
|
62
101
|
});
|
|
63
102
|
|
|
64
|
-
|
|
65
|
-
release.publishedStoreIds.push(storeId);
|
|
66
|
-
|
|
67
|
-
await releaseState.update(
|
|
68
|
-
{ id: releaseId },
|
|
69
|
-
{ $set: { publishedStoreIds: Array.from(new Set(release.publishedStoreIds)) } }
|
|
70
|
-
);
|
|
103
|
+
await updateReleaseWithRetry(releaseState, releaseId, projectId, storeId);
|
|
71
104
|
|
|
72
105
|
return response?.status;
|
|
73
106
|
};
|
|
@@ -11,14 +11,14 @@ const check = async (threshold) => {
|
|
|
11
11
|
for (const disk of disks) {
|
|
12
12
|
const usageRatio = (disk.used / disk.total) * 100;
|
|
13
13
|
if (Number.isNaN(usageRatio)) {
|
|
14
|
-
|
|
14
|
+
continue;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const usageRatioPercent = `${usageRatio.toFixed(2)}%`;
|
|
18
18
|
logger.info('check disk usage', { usage: usageRatioPercent, threshold });
|
|
19
19
|
|
|
20
20
|
if (usageRatio < threshold) {
|
|
21
|
-
|
|
21
|
+
continue;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line no-await-in-loop
|
package/lib/states/project.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.29-beta-
|
|
6
|
+
"version": "1.16.29-beta-1fb308f8",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/analytics": "1.16.29-beta-
|
|
23
|
-
"@abtnode/auth": "1.16.29-beta-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.29-beta-
|
|
25
|
-
"@abtnode/constant": "1.16.29-beta-
|
|
26
|
-
"@abtnode/cron": "1.16.29-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.29-beta-
|
|
28
|
-
"@abtnode/models": "1.16.29-beta-
|
|
29
|
-
"@abtnode/queue": "1.16.29-beta-
|
|
30
|
-
"@abtnode/rbac": "1.16.29-beta-
|
|
31
|
-
"@abtnode/router-provider": "1.16.29-beta-
|
|
32
|
-
"@abtnode/static-server": "1.16.29-beta-
|
|
33
|
-
"@abtnode/timemachine": "1.16.29-beta-
|
|
34
|
-
"@abtnode/util": "1.16.29-beta-
|
|
22
|
+
"@abtnode/analytics": "1.16.29-beta-1fb308f8",
|
|
23
|
+
"@abtnode/auth": "1.16.29-beta-1fb308f8",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.29-beta-1fb308f8",
|
|
25
|
+
"@abtnode/constant": "1.16.29-beta-1fb308f8",
|
|
26
|
+
"@abtnode/cron": "1.16.29-beta-1fb308f8",
|
|
27
|
+
"@abtnode/logger": "1.16.29-beta-1fb308f8",
|
|
28
|
+
"@abtnode/models": "1.16.29-beta-1fb308f8",
|
|
29
|
+
"@abtnode/queue": "1.16.29-beta-1fb308f8",
|
|
30
|
+
"@abtnode/rbac": "1.16.29-beta-1fb308f8",
|
|
31
|
+
"@abtnode/router-provider": "1.16.29-beta-1fb308f8",
|
|
32
|
+
"@abtnode/static-server": "1.16.29-beta-1fb308f8",
|
|
33
|
+
"@abtnode/timemachine": "1.16.29-beta-1fb308f8",
|
|
34
|
+
"@abtnode/util": "1.16.29-beta-1fb308f8",
|
|
35
35
|
"@arcblock/did": "1.18.126",
|
|
36
36
|
"@arcblock/did-auth": "1.18.126",
|
|
37
37
|
"@arcblock/did-ext": "^1.18.126",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"@arcblock/pm2-events": "^0.0.5",
|
|
43
43
|
"@arcblock/validator": "^1.18.126",
|
|
44
44
|
"@arcblock/vc": "1.18.126",
|
|
45
|
-
"@blocklet/constant": "1.16.29-beta-
|
|
46
|
-
"@blocklet/env": "1.16.29-beta-
|
|
47
|
-
"@blocklet/meta": "1.16.29-beta-
|
|
48
|
-
"@blocklet/resolver": "1.16.29-beta-
|
|
49
|
-
"@blocklet/sdk": "1.16.29-beta-
|
|
50
|
-
"@blocklet/store": "1.16.29-beta-
|
|
51
|
-
"@did-space/client": "^0.5.
|
|
45
|
+
"@blocklet/constant": "1.16.29-beta-1fb308f8",
|
|
46
|
+
"@blocklet/env": "1.16.29-beta-1fb308f8",
|
|
47
|
+
"@blocklet/meta": "1.16.29-beta-1fb308f8",
|
|
48
|
+
"@blocklet/resolver": "1.16.29-beta-1fb308f8",
|
|
49
|
+
"@blocklet/sdk": "1.16.29-beta-1fb308f8",
|
|
50
|
+
"@blocklet/store": "1.16.29-beta-1fb308f8",
|
|
51
|
+
"@did-space/client": "^0.5.12",
|
|
52
52
|
"@fidm/x509": "^1.2.1",
|
|
53
53
|
"@ocap/mcrypto": "1.18.126",
|
|
54
54
|
"@ocap/util": "1.18.126",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"jest": "^29.7.0",
|
|
104
104
|
"unzipper": "^0.10.11"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "1bf1d605a02f4df2789215e6e9518a62b1c3f806"
|
|
107
107
|
}
|