@blaxel/core 0.2.29-preview.67 → 0.2.29-preview.68
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.
|
@@ -4,13 +4,14 @@ import { DeleteProcessByIdentifierKillResponse, DeleteProcessByIdentifierRespons
|
|
|
4
4
|
import { ProcessRequestWithLog, ProcessResponseWithLog } from "../types.js";
|
|
5
5
|
export declare class SandboxProcess extends SandboxAction {
|
|
6
6
|
constructor(sandbox: Sandbox);
|
|
7
|
-
streamLogs(
|
|
7
|
+
streamLogs(processName: string, options?: {
|
|
8
8
|
onLog?: (log: string) => void;
|
|
9
9
|
onStdout?: (stdout: string) => void;
|
|
10
10
|
onStderr?: (stderr: string) => void;
|
|
11
11
|
}): {
|
|
12
12
|
close: () => void;
|
|
13
13
|
};
|
|
14
|
+
private _streamLogs;
|
|
14
15
|
exec(process: ProcessRequest | ProcessRequestWithLog): Promise<PostProcessResponse | ProcessResponseWithLog>;
|
|
15
16
|
wait(identifier: string, { maxWait, interval }?: {
|
|
16
17
|
maxWait?: number;
|
|
@@ -8,7 +8,74 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
8
8
|
constructor(sandbox) {
|
|
9
9
|
super(sandbox);
|
|
10
10
|
}
|
|
11
|
-
streamLogs(
|
|
11
|
+
streamLogs(processName, options = {}) {
|
|
12
|
+
const reconnectInterval = 30000;
|
|
13
|
+
let currentStream = null;
|
|
14
|
+
let isRunning = true;
|
|
15
|
+
let reconnectTimer = null;
|
|
16
|
+
// Track seen logs to avoid duplicates
|
|
17
|
+
const seenLogs = new Set();
|
|
18
|
+
const startStream = () => {
|
|
19
|
+
let logCounter = 0;
|
|
20
|
+
// Close existing stream if any
|
|
21
|
+
if (currentStream) {
|
|
22
|
+
currentStream.close();
|
|
23
|
+
}
|
|
24
|
+
// Start new stream with deduplication
|
|
25
|
+
currentStream = this._streamLogs(processName, {
|
|
26
|
+
onLog: (log) => {
|
|
27
|
+
const logKey = `${logCounter++}:${log}`;
|
|
28
|
+
if (!seenLogs.has(logKey)) {
|
|
29
|
+
seenLogs.add(logKey);
|
|
30
|
+
options.onLog?.(log);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
onStdout: (stdout) => {
|
|
34
|
+
const logKey = `${logCounter++}:${stdout}`;
|
|
35
|
+
if (!seenLogs.has(logKey)) {
|
|
36
|
+
seenLogs.add(logKey);
|
|
37
|
+
options.onStdout?.(stdout);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
onStderr: (stderr) => {
|
|
41
|
+
const logKey = `${logCounter++}:${stderr}`;
|
|
42
|
+
if (!seenLogs.has(logKey)) {
|
|
43
|
+
seenLogs.add(logKey);
|
|
44
|
+
options.onStderr?.(stderr);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
// Schedule next reconnection
|
|
49
|
+
if (isRunning) {
|
|
50
|
+
reconnectTimer = setTimeout(() => {
|
|
51
|
+
if (isRunning) {
|
|
52
|
+
startStream();
|
|
53
|
+
}
|
|
54
|
+
}, reconnectInterval);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// Start the initial stream
|
|
58
|
+
startStream();
|
|
59
|
+
// Return control functions
|
|
60
|
+
return {
|
|
61
|
+
close: async () => {
|
|
62
|
+
isRunning = false;
|
|
63
|
+
// Clear reconnect timer
|
|
64
|
+
if (reconnectTimer) {
|
|
65
|
+
clearTimeout(reconnectTimer);
|
|
66
|
+
reconnectTimer = null;
|
|
67
|
+
}
|
|
68
|
+
// Close current stream
|
|
69
|
+
if (currentStream) {
|
|
70
|
+
currentStream.close();
|
|
71
|
+
currentStream = null;
|
|
72
|
+
}
|
|
73
|
+
// Clear seen logs
|
|
74
|
+
seenLogs.clear();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
_streamLogs(identifier, options) {
|
|
12
79
|
const controller = new AbortController();
|
|
13
80
|
void (async () => {
|
|
14
81
|
try {
|