@vectorasystems/cli 0.2.1 → 0.2.2
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/package.json +1 -1
- package/src/lib/sse-client.js +26 -7
package/package.json
CHANGED
package/src/lib/sse-client.js
CHANGED
|
@@ -48,15 +48,34 @@ export async function* parseSseStream(body) {
|
|
|
48
48
|
* @yields {{ event: string, data: object }}
|
|
49
49
|
*/
|
|
50
50
|
export async function* streamPhaseProgress(baseUrl, jobId, token) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
51
|
+
while (true) {
|
|
52
|
+
const res = await fetch(`${baseUrl}/v1/phases/${jobId}?token=${token}`);
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
if (!res.ok || !res.body) {
|
|
55
|
+
throw new Error(`Phase SSE failed: HTTP ${res.status}`);
|
|
56
|
+
}
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
let reconnect = false;
|
|
59
|
+
|
|
60
|
+
for await (const frame of parseSseStream(res.body)) {
|
|
61
|
+
if (frame.event === 'job:timeout') {
|
|
62
|
+
reconnect = true;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
yield frame;
|
|
67
|
+
|
|
68
|
+
if (frame.event === 'job:completed' || frame.event === 'job:failed') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!reconnect) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
78
|
+
}
|
|
60
79
|
}
|
|
61
80
|
|
|
62
81
|
/**
|