@blaxel/core 0.2.49-dev.212 → 0.2.49-dev.214
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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/jobs/start.js +32 -1
- package/dist/cjs/sandbox/process/process-ws.js +1 -1
- package/dist/cjs/sandbox/websocket/client.js +3 -9
- package/dist/cjs/types/sandbox/websocket/client.d.ts +0 -1
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/common/settings.js +2 -2
- package/dist/cjs-browser/jobs/start.js +32 -1
- package/dist/cjs-browser/sandbox/process/process-ws.js +1 -1
- package/dist/cjs-browser/sandbox/websocket/client.js +3 -9
- package/dist/cjs-browser/types/sandbox/websocket/client.d.ts +0 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/jobs/start.js +32 -1
- package/dist/esm/sandbox/process/process-ws.js +1 -1
- package/dist/esm/sandbox/websocket/client.js +3 -9
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/common/settings.js +2 -2
- package/dist/esm-browser/jobs/start.js +32 -1
- package/dist/esm-browser/sandbox/process/process-ws.js +1 -1
- package/dist/esm-browser/sandbox/websocket/client.js +3 -9
- package/package.json +2 -2
|
@@ -2,12 +2,43 @@ import { authenticate } from '../common/autoload.js';
|
|
|
2
2
|
import { env } from '../common/env.js';
|
|
3
3
|
import { flush } from '../telemetry/telemetry.js';
|
|
4
4
|
class BlJobWrapper {
|
|
5
|
+
async fetchWithRetry(url, maxRetries = 3) {
|
|
6
|
+
let lastError;
|
|
7
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
8
|
+
try {
|
|
9
|
+
const response = await fetch(url);
|
|
10
|
+
// If the response is successful, return it
|
|
11
|
+
if (response.ok) {
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
// If it's not the last attempt and the status is retriable, retry
|
|
15
|
+
if (attempt < maxRetries && (response.status >= 500 || response.status === 429)) {
|
|
16
|
+
lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// For non-retriable errors or last attempt, return the response
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
25
|
+
// If this is the last attempt, throw the error
|
|
26
|
+
if (attempt === maxRetries) {
|
|
27
|
+
throw lastError;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Calculate exponential backoff delay: 2^attempt * 1000ms (1s, 2s, 4s)
|
|
31
|
+
const delay = Math.pow(2, attempt) * 1000;
|
|
32
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
33
|
+
}
|
|
34
|
+
throw lastError || new Error('Failed to fetch after retries');
|
|
35
|
+
}
|
|
5
36
|
async getArguments() {
|
|
6
37
|
if (!env.BL_EXECUTION_DATA_URL) {
|
|
7
38
|
const args = this.parseCommandLineArgs();
|
|
8
39
|
return args;
|
|
9
40
|
}
|
|
10
|
-
const response = await
|
|
41
|
+
const response = await this.fetchWithRetry(env.BL_EXECUTION_DATA_URL);
|
|
11
42
|
const data = await response.json();
|
|
12
43
|
return data.tasks[this.index] ?? {};
|
|
13
44
|
}
|
|
@@ -107,7 +107,7 @@ export class SandboxProcessWebSocket extends SandboxAction {
|
|
|
107
107
|
}
|
|
108
108
|
async list() {
|
|
109
109
|
const data = await this.wsClient.send("process:list", {});
|
|
110
|
-
return data;
|
|
110
|
+
return data.processes || [];
|
|
111
111
|
}
|
|
112
112
|
async stop(identifier) {
|
|
113
113
|
const data = await this.wsClient.send("process:stop", { identifier });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from "uuid";
|
|
2
2
|
import { getWebSocket } from "../../common/node.js";
|
|
3
|
+
import { settings } from "../../common/settings.js";
|
|
3
4
|
export class WebSocketClient {
|
|
4
5
|
ws = null;
|
|
5
6
|
WebSocketClass = null;
|
|
6
7
|
url;
|
|
7
|
-
headers;
|
|
8
8
|
reconnect;
|
|
9
9
|
reconnectInterval;
|
|
10
10
|
maxReconnectAttempts;
|
|
@@ -18,7 +18,6 @@ export class WebSocketClient {
|
|
|
18
18
|
lastPongReceived = Date.now();
|
|
19
19
|
constructor(options) {
|
|
20
20
|
this.url = options.url;
|
|
21
|
-
this.headers = options.headers || {};
|
|
22
21
|
this.reconnect = options.reconnect ?? true;
|
|
23
22
|
this.reconnectInterval = options.reconnectInterval ?? 5000;
|
|
24
23
|
this.maxReconnectAttempts = options.maxReconnectAttempts ?? 5;
|
|
@@ -52,14 +51,9 @@ export class WebSocketClient {
|
|
|
52
51
|
if (!wsUrl.endsWith("/ws")) {
|
|
53
52
|
wsUrl = `${wsUrl}/ws`;
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
const wsOptions = {};
|
|
57
|
-
if (Object.keys(this.headers).length > 0) {
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
59
|
-
wsOptions.headers = this.headers;
|
|
60
|
-
}
|
|
54
|
+
wsUrl = `${wsUrl}?token=${settings.token}`;
|
|
61
55
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
62
|
-
this.ws = new this.WebSocketClass(wsUrl
|
|
56
|
+
this.ws = new this.WebSocketClass(wsUrl);
|
|
63
57
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
64
58
|
this.ws.onopen = () => {
|
|
65
59
|
this.reconnectAttempts = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/core",
|
|
3
|
-
"version": "0.2.49-dev.
|
|
3
|
+
"version": "0.2.49-dev.214",
|
|
4
4
|
"description": "Blaxel Core SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"vite": "^5.2.0",
|
|
75
75
|
"vitest": "^1.5.0"
|
|
76
76
|
},
|
|
77
|
-
"commit": "
|
|
77
|
+
"commit": "3cd25c395e498b34304684d4d76a906f2cef14a9",
|
|
78
78
|
"scripts": {
|
|
79
79
|
"lint": "eslint src/",
|
|
80
80
|
"dev": "tsc --watch",
|