Worker Tasks
Worker tasks enable distributed task processing where multiple contributors can submit results for the same task. The system supports consensus-based resolution where multiple result submissions are collected and compared. Tasks can be accessed via both /worker/tasks and /contributor/tasks routes.
Endpoints
List Tasks
GET /api/v2/worker/tasks
GET /api/v2/contributor/tasks
Retrieves a paginated list of worker tasks for the current user.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| client_account_id | integer | No | Filter by client account ID |
| status | string | No | Filter by status (default: PENDING) |
| task_type | string | No | Filter by task type (comma, semicolon, or space separated for multiple) |
| has_submitted_results | boolean | No | Filter tasks that have submitted results |
| has_results_from_id | integer | No | Filter tasks with results from a specific user |
| has_no_results_from_id | integer | No | Filter tasks without results from a specific user |
| less_than_results_from_me | integer | No | Filter tasks with fewer results from current user than threshold |
| downplay_results_from_id | integer | No | De-prioritize tasks with results from a specific user |
| order_by | string | No | Sort field |
| page | integer | No | Page number (default: 1) |
| per_page | integer | No | Items per page (default: 100) |
Response
{
"data": [
{
"id": 1,
"created_at": "2024-03-15T10:00:00Z",
"created_by_id": 7,
"completed_at": null,
"status": "PENDING",
"task_type": "document_classification",
"relation_type": "voucher",
"relation_id": 123,
"secondary_relation_type": null,
"secondary_relation_id": null,
"comment": "Classify this document"
}
],
"meta": {
"page": 1,
"pages": 1,
"per_page": 100,
"records": 1
}
}
Get Task
GET /api/v2/contributor/tasks/{id}
Retrieves a specific worker task by ID.
Create Task
POST /api/v2/contributor/tasks
Creates a new worker task.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| task_type | string | Yes | Type of task to create |
| status | string | No | Initial status |
| relation_type | string | No | Type of related entity |
| relation_id | integer | No | ID of related entity |
| secondary_relation_type | string | No | Type of secondary related entity |
| secondary_relation_id | integer | No | ID of secondary related entity |
| comment | string | No | Description or instructions |
Response
Returns the created task with status 201 Created.
Update Task
PATCH /api/v2/contributor/tasks/{id}
Updates a worker task. Currently only supports cancelling a pending task.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| status | string | Yes | New status. Only CANCELLED is allowed, and only when current status is PENDING |
Response
Returns the updated task.
Submit Result
POST /api/v2/worker/tasks/{id}/results
POST /api/v2/contributor/tasks/{id}/results
Submits a result for a worker task. Multiple users can submit results for the same task.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| data | object | Yes | Result data (structure depends on task type) |
Response
{
"id": 1,
"submitted_at": "2024-03-15T11:00:00Z",
"submitted_by_id": 7,
"task_id": 1,
"status": "SUBMITTED",
"data": {
"classification": "invoice",
"confidence": 0.95
}
}
Attributes
Worker Task
| Attribute | Type | Description |
|---|---|---|
| id | integer | Unique identifier (read-only) |
| created_at | datetime | Creation timestamp (read-only) |
| created_by_id | integer | ID of the creating user (read-only) |
| completed_at | datetime | Completion timestamp (read-only) |
| status | string | Task status: PENDING, COMPLETED, or CANCELLED |
| task_type | string | Type of task |
| relation_type | string | Type of related entity |
| relation_id | integer | ID of related entity |
| secondary_relation_type | string | Type of secondary related entity |
| secondary_relation_id | integer | ID of secondary related entity |
| comment | string | Task description or instructions |
Worker Task Result
| Attribute | Type | Description |
|---|---|---|
| id | integer | Unique identifier (read-only) |
| submitted_at | datetime | Submission timestamp (read-only) |
| submitted_by_id | integer | ID of the submitting user (read-only) |
| task_id | integer | ID of the parent task (read-only) |
| status | string | Result status: SUBMITTED |
| data | object | Result data |
Relationships
| Relationship | Type | Description |
|---|---|---|
| results | WorkerTaskResult[] | All submitted results for the task |
| consensus | WorkerTaskResult | The consensus result (if reached) |
Business Rules
- Only
PENDINGtasks can be cancelled - Results cannot be submitted for
COMPLETEDtasks - Multiple users can submit results for the same task (consensus-based)
- Tasks are automatically filtered to the current user’s scope
Error Responses
| Status Code | Description |
|---|---|
| 400 | Invalid request (e.g., trying to cancel a non-pending task, submitting results for completed task) |
| 403 | Forbidden (no access to client account) |
| 404 | Task not found |