Async Jobs
Async Jobs provide a server-based approach to running recipes and agents. Jobs are submitted to an API server, persisted, and can be monitored, streamed, and cancelled. Ideal for production deployments with multiple clients.Python API
Submitting a Job
JobHandle Methods
| Method | Description |
|---|---|
job_id | Unique job identifier |
recipe_name | Name of the recipe being executed |
status | Current job status |
get_status() | Fetch current status from API |
get_result() | Fetch job result from API |
cancel() | Cancel the job |
wait(poll_interval, timeout) | Wait for completion |
Waiting for Completion
Using the Jobs API Directly
Starting the Jobs Server
Server Configuration
| Environment Variable | Default | Description |
|---|---|---|
PRAISONAI_JOBS_PORT | 8005 | Server port |
PRAISONAI_JOBS_HOST | 127.0.0.1 | Server host |
PRAISONAI_JOBS_MAX_CONCURRENT | 10 | Max concurrent jobs |
PRAISONAI_JOBS_DEFAULT_TIMEOUT | 3600 | Default timeout (seconds) |
Job Status Values
queued- Job is waiting to be processedrunning- Job is currently executingsucceeded- Job completed successfullyfailed- Job failed with an errorcancelled- Job was cancelled
Webhooks
Configure webhooks to receive notifications when jobs complete:Idempotency
Prevent duplicate job submissions with idempotency keys:Idempotency Scopes
| Scope | Description |
|---|---|
none | No idempotency (default) |
session | Unique within session |
global | Unique across all sessions |
TEMPLATE.yaml Runtime Block
Configure job defaults in your recipe:Error Handling
Best Practices
- Use idempotency keys - Prevent duplicate submissions
- Set appropriate timeouts - Match job complexity
- Configure webhooks - For async notification
- Monitor job status - Use streaming for real-time updates
- Handle failures gracefully - Implement retry logic
See Also
- Async Jobs CLI - CLI commands for jobs
- Background Tasks - In-process background execution
- Scheduler - Periodic job scheduling

