@abtnode/core 1.16.54-beta-20251029-055649-a9143beb → 1.16.54-beta-20251029-230008-54c9843b

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.
@@ -2656,6 +2656,12 @@ class DiskBlockletManager extends BaseBlockletManager {
2656
2656
  options: { runOnInit: false },
2657
2657
  fn: () => this.cleanExpiredBlocklets(),
2658
2658
  },
2659
+ {
2660
+ name: 'send-serverless-heartbeat',
2661
+ time: process.env.ABT_NODE_SERVERLESS_HEARTBEAT_INTERVAL || '*/5 * * * *', // default every 5 minutes
2662
+ options: { runOnInit: false },
2663
+ fn: () => launcher.sendServerlessHeartbeat(),
2664
+ },
2659
2665
  ];
2660
2666
 
2661
2667
  logger.info('enable serverless jobs', serverlessJobs.map((x) => x.name).join(','));
@@ -7,6 +7,7 @@ const pick = require('lodash/pick');
7
7
  const uniq = require('lodash/uniq');
8
8
  const trim = require('lodash/trim');
9
9
  const merge = require('lodash/merge');
10
+ const si = require('systeminformation');
10
11
  const isEmpty = require('lodash/isEmpty');
11
12
  const {
12
13
  getUserAvatarUrl,
@@ -156,6 +157,85 @@ const notifyBlockletUpdated = (blocklet) => notifyLauncher('serverless.blocklet.
156
157
  const notifyBlockletStarted = (blocklet) => notifyLauncher('serverless.blocklet.started', blocklet);
157
158
  const notifyBlockletStopped = (blocklet) => notifyLauncher('serverless.blocklet.stopped', blocklet);
158
159
 
160
+ const getCpuUtilization = async () => {
161
+ const load = await si.currentLoad();
162
+ const u = Number(load?.currentLoad);
163
+
164
+ return Math.max(0, Math.min(1, u / 100));
165
+ };
166
+
167
+ const getComponentsAggregate = async () => {
168
+ try {
169
+ const list = await states.blocklet.getBlocklets();
170
+ const counts = {};
171
+ let total = 0;
172
+ list.forEach((b) => {
173
+ const children = Array.isArray(b.children) ? b.children : [];
174
+ children.forEach((child) => {
175
+ const key = fromBlockletStatus(child.status) || 'unknown';
176
+ counts[key] = (counts[key] || 0) + 1;
177
+ total += 1;
178
+ });
179
+ });
180
+
181
+ return { total, counts };
182
+ } catch (error) {
183
+ logger.error('getComponentsAggregate failed', { error });
184
+ return { total: 0, counts: {} };
185
+ }
186
+ };
187
+
188
+ const sendServerlessHeartbeat = async () => {
189
+ logger.info('send serverless heartbeat');
190
+ const nodeInfo = await states.node.read();
191
+ const launcherUrl = nodeInfo?.launcher?.url;
192
+ if (!launcherUrl) {
193
+ logger.error('skip heartbeat: launcher url not configured', {
194
+ launcher: nodeInfo?.launcher,
195
+ });
196
+ return null;
197
+ }
198
+
199
+ const { did } = nodeInfo;
200
+ const cpuCores = os.cpus().length;
201
+ const [mem, cpuUtilization, components] = await Promise.all([
202
+ si.mem(),
203
+ getCpuUtilization(),
204
+ getComponentsAggregate(),
205
+ ]);
206
+
207
+ const memoryAvailableMb = mem.available / 1024 / 1024;
208
+ const memoryTotalMb = mem.total / 1024 / 1024;
209
+
210
+ const payload = {
211
+ name: nodeInfo.name,
212
+ description: nodeInfo.description,
213
+ version,
214
+ did,
215
+ cpuUtilization,
216
+ memoryAvailableMb,
217
+ memoryTotalMb,
218
+ cpuCores,
219
+ components,
220
+ };
221
+
222
+ logger.debug('send serverless heartbeat payload', { did, launcherUrl, payload });
223
+
224
+ try {
225
+ const result = await doRequest(nodeInfo.sk, {
226
+ launcherUrl,
227
+ pathname: '/api/serverless/heartbeat',
228
+ payload,
229
+ method: 'post',
230
+ });
231
+ logger.info('sent heartbeat to launcher', { did, launcherUrl, result });
232
+ return result;
233
+ } catch (error) {
234
+ logger.error('send heartbeat failed', { error: error.message, did, launcherUrl });
235
+ return null;
236
+ }
237
+ };
238
+
159
239
  const consumeLauncherSession = async ({ params, blocklet }) => {
160
240
  try {
161
241
  const info = await states.node.read();
@@ -657,4 +737,5 @@ module.exports = {
657
737
  notifyBlockletStopped,
658
738
  launchBlockletByLauncher,
659
739
  launchBlockletWithoutWallet,
740
+ sendServerlessHeartbeat,
660
741
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.54-beta-20251029-055649-a9143beb",
6
+ "version": "1.16.54-beta-20251029-230008-54c9843b",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,21 +19,21 @@
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.54-beta-20251029-055649-a9143beb",
23
- "@abtnode/auth": "1.16.54-beta-20251029-055649-a9143beb",
24
- "@abtnode/certificate-manager": "1.16.54-beta-20251029-055649-a9143beb",
25
- "@abtnode/constant": "1.16.54-beta-20251029-055649-a9143beb",
26
- "@abtnode/cron": "1.16.54-beta-20251029-055649-a9143beb",
27
- "@abtnode/db-cache": "1.16.54-beta-20251029-055649-a9143beb",
28
- "@abtnode/docker-utils": "1.16.54-beta-20251029-055649-a9143beb",
29
- "@abtnode/logger": "1.16.54-beta-20251029-055649-a9143beb",
30
- "@abtnode/models": "1.16.54-beta-20251029-055649-a9143beb",
31
- "@abtnode/queue": "1.16.54-beta-20251029-055649-a9143beb",
32
- "@abtnode/rbac": "1.16.54-beta-20251029-055649-a9143beb",
33
- "@abtnode/router-provider": "1.16.54-beta-20251029-055649-a9143beb",
34
- "@abtnode/static-server": "1.16.54-beta-20251029-055649-a9143beb",
35
- "@abtnode/timemachine": "1.16.54-beta-20251029-055649-a9143beb",
36
- "@abtnode/util": "1.16.54-beta-20251029-055649-a9143beb",
22
+ "@abtnode/analytics": "1.16.54-beta-20251029-230008-54c9843b",
23
+ "@abtnode/auth": "1.16.54-beta-20251029-230008-54c9843b",
24
+ "@abtnode/certificate-manager": "1.16.54-beta-20251029-230008-54c9843b",
25
+ "@abtnode/constant": "1.16.54-beta-20251029-230008-54c9843b",
26
+ "@abtnode/cron": "1.16.54-beta-20251029-230008-54c9843b",
27
+ "@abtnode/db-cache": "1.16.54-beta-20251029-230008-54c9843b",
28
+ "@abtnode/docker-utils": "1.16.54-beta-20251029-230008-54c9843b",
29
+ "@abtnode/logger": "1.16.54-beta-20251029-230008-54c9843b",
30
+ "@abtnode/models": "1.16.54-beta-20251029-230008-54c9843b",
31
+ "@abtnode/queue": "1.16.54-beta-20251029-230008-54c9843b",
32
+ "@abtnode/rbac": "1.16.54-beta-20251029-230008-54c9843b",
33
+ "@abtnode/router-provider": "1.16.54-beta-20251029-230008-54c9843b",
34
+ "@abtnode/static-server": "1.16.54-beta-20251029-230008-54c9843b",
35
+ "@abtnode/timemachine": "1.16.54-beta-20251029-230008-54c9843b",
36
+ "@abtnode/util": "1.16.54-beta-20251029-230008-54c9843b",
37
37
  "@aigne/aigne-hub": "^0.10.3",
38
38
  "@arcblock/did": "^1.26.3",
39
39
  "@arcblock/did-connect-js": "^1.26.3",
@@ -45,15 +45,15 @@
45
45
  "@arcblock/pm2-events": "^0.0.5",
46
46
  "@arcblock/validator": "^1.26.3",
47
47
  "@arcblock/vc": "^1.26.3",
48
- "@blocklet/constant": "1.16.54-beta-20251029-055649-a9143beb",
48
+ "@blocklet/constant": "1.16.54-beta-20251029-230008-54c9843b",
49
49
  "@blocklet/did-space-js": "^1.1.35",
50
- "@blocklet/env": "1.16.54-beta-20251029-055649-a9143beb",
50
+ "@blocklet/env": "1.16.54-beta-20251029-230008-54c9843b",
51
51
  "@blocklet/error": "^0.2.5",
52
- "@blocklet/meta": "1.16.54-beta-20251029-055649-a9143beb",
53
- "@blocklet/resolver": "1.16.54-beta-20251029-055649-a9143beb",
54
- "@blocklet/sdk": "1.16.54-beta-20251029-055649-a9143beb",
55
- "@blocklet/server-js": "1.16.54-beta-20251029-055649-a9143beb",
56
- "@blocklet/store": "1.16.54-beta-20251029-055649-a9143beb",
52
+ "@blocklet/meta": "1.16.54-beta-20251029-230008-54c9843b",
53
+ "@blocklet/resolver": "1.16.54-beta-20251029-230008-54c9843b",
54
+ "@blocklet/sdk": "1.16.54-beta-20251029-230008-54c9843b",
55
+ "@blocklet/server-js": "1.16.54-beta-20251029-230008-54c9843b",
56
+ "@blocklet/store": "1.16.54-beta-20251029-230008-54c9843b",
57
57
  "@blocklet/theme": "^3.1.53",
58
58
  "@fidm/x509": "^1.2.1",
59
59
  "@ocap/mcrypto": "^1.26.3",
@@ -118,5 +118,5 @@
118
118
  "express": "^4.18.2",
119
119
  "unzipper": "^0.10.11"
120
120
  },
121
- "gitHead": "4ac4eebb4ade000c0fca21b1d542054a9dafd776"
121
+ "gitHead": "21cf7881f5759a9b82e1a852286f048af112bafa"
122
122
  }