You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add process readiness documentation for sandbox SDK
Syncs documentation for PR #273: process readiness feature
Changes:
- Add comprehensive process readiness section to background-processes guide
- Document new serve() method for starting servers with readiness checks
- Document Process.waitFor() method for waiting on conditions
- Update startProcess() API with ready and readyTimeout options
- Add ReadyCondition, WaitForResult, and ServeOptions type documentation
- Document ProcessReadyTimeoutError and ProcessExitedBeforeReadyError
- Update examples to use new readiness API instead of manual log streaming
- Simplify multi-process startup examples with inline readiness checks
Generated with Claude Code (https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
for await (const log of parseSSEStream<LogEvent>(dbLogs)) {
148
-
if (log.data.includes('Ready to accept connections')) {
149
-
break;
150
-
}
151
-
}
207
+
const db = await sandbox.startProcess('redis-server', {
208
+
ready: 'Ready to accept connections'
209
+
});
152
210
153
211
// Now start API server (depends on database)
154
212
const api = await sandbox.startProcess('node api-server.js', {
213
+
ready: 'API server listening',
155
214
env: { DATABASE_URL: 'redis://localhost:6379' }
156
215
});
157
216
158
217
console.log('All services running');
159
218
```
160
219
</TypeScriptExample>
161
220
221
+
Or wait for port availability:
222
+
223
+
<TypeScriptExample>
224
+
```
225
+
// Start database and wait for port
226
+
const db = await sandbox.startProcess('redis-server', {
227
+
ready: 6379
228
+
});
229
+
230
+
// Start API and wait for both log pattern and port
231
+
const api = await sandbox.startProcess('npm start');
232
+
await api.waitFor('Database connected');
233
+
await api.waitFor(3000);
234
+
235
+
console.log('API is fully ready');
236
+
```
237
+
</TypeScriptExample>
238
+
162
239
## Keep containers alive for long-running processes
163
240
164
241
By default, containers automatically shut down after 10 minutes of inactivity. For long-running processes that may have idle periods (like CI/CD pipelines, batch jobs, or monitoring tasks), use the [`keepAlive` option](/sandbox/configuration/sandbox-options/#keepalive):
@@ -207,9 +284,9 @@ When using `keepAlive: true`, containers will not automatically timeout. You **m
207
284
208
285
## Best practices
209
286
210
-
-**Wait for readiness** - Stream logs to detect when services are ready
287
+
-**Wait for readiness** - Use `waitFor()` or the `ready` option to ensure processes are fully started
211
288
-**Clean up** - Always stop processes when done
212
-
-**Handle failures** - Monitor logs for errors and restart if needed
289
+
-**Handle failures** - Catch readiness errors and check logs for diagnostics
213
290
-**Use try/finally** - Ensure cleanup happens even on errors
214
291
-**Use `keepAlive` for long-running tasks** - Prevent container shutdown during processes with idle periods
0 commit comments