feat(jobs): add background job support for benchmarks and processing
Why: - Long benchmark and process runs block HTTP clients; task #20 required async execution. Changes: - SQLite jobs table + GET /jobs and GET /jobs/{id} - POST /benchmarks?background=true and POST /documents/{id}/process?background=true return 202 + job_id - FastAPI BackgroundTasks execute work in-process; sync paths unchanged Impact: - Jobs are lost on server restart (Option A, no external queue) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -82,6 +82,9 @@ Delete a document and its vectors.
|
||||
|
||||
Run chunking strategies on a document.
|
||||
|
||||
**Query parameters:**
|
||||
- `background` (bool, default `false`) — when `true`, enqueue processing and return **202** with a `job_id`; poll `GET /jobs/{job_id}`.
|
||||
|
||||
**Request:**
|
||||
```json
|
||||
{
|
||||
@@ -199,6 +202,9 @@ Retrieve a past query.
|
||||
|
||||
Run a benchmark comparing multiple strategies.
|
||||
|
||||
**Query parameters:**
|
||||
- `background` (bool, default `false`) — when `true`, enqueue the run and return **202** with a `job_id`; poll `GET /jobs/{job_id}` for status and result.
|
||||
|
||||
**Request:**
|
||||
```json
|
||||
{
|
||||
@@ -278,6 +284,32 @@ List all experiments.
|
||||
|
||||
---
|
||||
|
||||
### Jobs
|
||||
|
||||
Background execution for long-running benchmarks and document processing (FastAPI `BackgroundTasks` + SQLite job records).
|
||||
|
||||
#### `GET /jobs`
|
||||
|
||||
List jobs (newest first).
|
||||
|
||||
**Query parameters:** `job_type`, `status`, `offset`, `limit`
|
||||
|
||||
#### `GET /jobs/{job_id}`
|
||||
|
||||
Poll job status. When `status` is `completed`, `result` contains the same payload as the synchronous endpoint would return; when `failed`, `error` is set.
|
||||
|
||||
**Response (202 enqueue body from POST with `background=true`):**
|
||||
```json
|
||||
{
|
||||
"job_id": "abc123",
|
||||
"job_type": "benchmark",
|
||||
"status": "pending",
|
||||
"poll_url": "/jobs/abc123"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Responses
|
||||
|
||||
All errors return:
|
||||
|
||||
Reference in New Issue
Block a user