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
Documents the new process readiness feature added in PR #273, including:
- waitFor() method for waiting on log patterns, regex, or ports
- serve() method for starting servers with automatic readiness checks
- ready and readyTimeout options for startProcess()
- ProcessReadyTimeoutError and ProcessExitedBeforeReadyError handling
Updates:
- Background processes guide with comprehensive readiness examples
- Commands API reference with new methods and options
🤖 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
-
}
257
+
// Start database and wait for it to be ready
258
+
const db = await sandbox.startProcess('redis-server', {
259
+
ready: 'Ready to accept connections'
260
+
});
152
261
153
262
// Now start API server (depends on database)
154
263
const api = await sandbox.startProcess('node api-server.js', {
155
-
env: { DATABASE_URL: 'redis://localhost:6379' }
264
+
env: { DATABASE_URL: 'redis://localhost:6379' },
265
+
ready: 'API server listening'
156
266
});
157
267
158
268
console.log('All services running');
159
269
```
160
270
</TypeScriptExample>
161
271
272
+
You can also wait for multiple conditions sequentially:
273
+
274
+
<TypeScriptExample>
275
+
```
276
+
const db = await sandbox.startProcess('postgres -D /data');
277
+
278
+
// Wait for multiple startup phases
279
+
await db.waitFor('database system is ready to accept connections');
280
+
await db.waitFor(5432); // Wait for port to be available
281
+
282
+
console.log('Database fully initialized');
283
+
```
284
+
</TypeScriptExample>
285
+
162
286
## Keep containers alive for long-running processes
163
287
164
288
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 +331,9 @@ When using `keepAlive: true`, containers will not automatically timeout. You **m
207
331
208
332
## Best practices
209
333
210
-
-**Wait for readiness** - Stream logs to detect when services are ready
334
+
-**Wait for readiness** - Use the `ready` option or `waitFor()` method to ensure services are ready before proceeding
211
335
-**Clean up** - Always stop processes when done
212
-
-**Handle failures** - Monitor logs for errors and restart if needed
336
+
-**Handle failures** - Catch `ProcessReadyTimeoutError` and `ProcessExitedBeforeReadyError` to handle startup issues
213
337
-**Use try/finally** - Ensure cleanup happens even on errors
214
338
-**Use `keepAlive` for long-running tasks** - Prevent container shutdown during processes with idle periods
0 commit comments