Architecture
The async processing flow works as follows:Implementation Pattern
Step 1: Initiate Job
Call an endpoint that creates an async job (e.g.POST /api/admin/prompts/preview). The endpoint returns immediately with:
202 AcceptedstatusjobId(UUID) to pollstatus: "PROCESSING"
Step 2: Poll Job Status
PollGET /api/jobs/:id every 3 seconds until status is COMPLETED or FAILED.
Step 3: Handle Results
Once the job status isCOMPLETED, extract the result field:
Retry Logic
Jobs automatically retry up to 3 times on failure:attemptsfield tracks retry countmaxAttemptsis set to 3 by default- After 3 failed attempts, status becomes
FAILED
Timeout Recommendations
Client-Side Timeout
Implement a maximum polling duration to avoid infinite loops:Expected Durations
| Job Type | Typical Duration |
|---|---|
AI_PREVIEW | 3-10 seconds |
PARSE_DOCUMENT | 5-30 seconds (depends on file size) |
GAP_DETECTION | 10-30 seconds |
RISK_ANALYSIS | 15-60 seconds (7 categories analyzed) |
REPORT_GENERATION | 20-90 seconds |
Best Practices
1. Exponential Backoff (Optional)
For production use, consider exponential backoff if the job is taking longer than expected:2. User Feedback
Show progress indicators while polling:3. Error Handling
Handle different failure scenarios:4. Cancellation
Allow users to cancel polling (jobs continue running in background):React Hook Example
Job Scoping
Jobs are scoped to the user who created them:- Job records include
createdByIdfield GET /api/jobs/:idonly returns jobs created by the authenticated user- Attempting to access another user’s job returns
404
Database Schema
Jobs are stored in thejobs table with the following fields:
See Also
- Get Job Status — API reference for
GET /api/jobs/:id - Preview Prompt — Example of job-creating endpoint