Goal
Create a script that connects to the engine, waits to process a task (e.g., generating a heavy report), and then gracefully shuts down.Context
This pattern is useful for executing resource-intensive or one-off tasks on serverless container platforms (like AWS Fargate or Kubernetes Jobs) where you want to minimize execution time and infrastructure costs.Steps
1. Initialize and Register
Connect to iii and register thereports::generate function handler to process the heavy CPU task.
- Node / TypeScript
- Python
- Rust
worker.ts
2. Trigger and Graceful Shutdown
The main thread connects, triggers the function, awaits its completion, then callsshutdown() (or shutdown_async().await in Rust for guaranteed telemetry flush) to cleanly close the WebSocket and exit the process.
- Node / TypeScript
- Python
- Rust
worker.ts
Result
When the script runs, it connects to the Engine, waits for a single invocation ofreports::generate, executes it, and cleanly disconnects and exits immediately after. This prevents zombie processes and automatically scales your infrastructure down once the heavy lifting is done.