openthrottle 0.1.14 → 0.1.15
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/run.js +22 -16
- package/package.json +1 -1
package/dist/run.js
CHANGED
|
@@ -107,26 +107,32 @@ export default async function run() {
|
|
|
107
107
|
});
|
|
108
108
|
console.log(`[run] Sandbox created: ${sandboxName}`);
|
|
109
109
|
console.log(`[run] Streaming logs (timeout: ${taskTimeout}s)...`);
|
|
110
|
-
// Stream entrypoint logs
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
]);
|
|
116
|
-
// Get exit code
|
|
110
|
+
// Stream entrypoint logs in background
|
|
111
|
+
sandbox.process.getEntrypointLogs((chunk) => process.stdout.write(chunk), (chunk) => process.stderr.write(chunk)).catch(() => { }); // stream may error when sandbox stops — that's fine
|
|
112
|
+
// Poll for entrypoint completion. getEntrypointLogs() may not resolve
|
|
113
|
+
// when the entrypoint exits because Daytona keeps the container alive.
|
|
114
|
+
const POLL_MS = 5_000;
|
|
117
115
|
let exitCode = 0;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
const deadline = Date.now() + taskTimeout * 1000;
|
|
117
|
+
while (Date.now() < deadline) {
|
|
118
|
+
await new Promise((r) => setTimeout(r, POLL_MS));
|
|
119
|
+
try {
|
|
120
|
+
const session = await sandbox.process.getEntrypointSession();
|
|
121
|
+
const commands = session?.commands || [];
|
|
122
|
+
if (commands.length > 0) {
|
|
123
|
+
const last = commands[commands.length - 1];
|
|
124
|
+
if (last.exitCode !== undefined && last.exitCode !== null) {
|
|
125
|
+
exitCode = last.exitCode;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
125
128
|
}
|
|
126
129
|
}
|
|
130
|
+
catch {
|
|
131
|
+
// sandbox may not be ready yet — keep polling
|
|
132
|
+
}
|
|
127
133
|
}
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
if (Date.now() >= deadline) {
|
|
135
|
+
throw new Error(`Task timeout (${taskTimeout}s) exceeded`);
|
|
130
136
|
}
|
|
131
137
|
console.log(`[run] Finished (exit code: ${exitCode})`);
|
|
132
138
|
await cleanup();
|