Implementation:Infiniflow Ragflow TaskService Get Task
Appearance
| Knowledge Sources | |
|---|---|
| Domains | RAG, Task_Queue |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete tool for hydrating task context from Redis queue messages provided by RAGFlow TaskService.
Description
TaskService.get_task takes a task ID from a Redis queue message and performs a multi-table JOIN across Task, Document, Knowledgebase, and Tenant to build a comprehensive task dictionary with 21 fields needed for document processing.
Usage
Called by the task executor worker after consuming a Redis message. Returns None if the task has exceeded retry limits.
Code Reference
Source Location
- Repository: ragflow
- File: api/db/services/task_service.py
- Lines: L74-142
Signature
class TaskService(CommonService):
@classmethod
@DB.connection_context()
def get_task(cls, task_id: str, doc_ids: list = []) -> dict | None:
"""Hydrate a task with full context from DB.
Args:
task_id: str - Task UUID from Redis message.
doc_ids: list - Optional document ID filter.
Returns:
dict with 21 fields (task + document + KB + tenant info) or None if retry_count >= 3.
"""
Import
from api.db.services.task_service import TaskService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| task_id | str | Yes | Task UUID from Redis message |
| doc_ids | list | No | Optional document ID filter |
Outputs
| Name | Type | Description |
|---|---|---|
| task_dict | dict or None | 21-field dict: task.id, task.doc_id, task.from_page, task.to_page, task.retry_count, Document.kb_id, Document.parser_id, Document.parser_config, Document.name, Document.type, Document.location, Document.size, Knowledgebase.tenant_id, Knowledgebase.language, Knowledgebase.embd_id, Knowledgebase.pagerank, kb_parser_config, Tenant.img2txt_id, Tenant.asr_id, Tenant.llm_id, task.update_time |
Usage Examples
from api.db.services.task_service import TaskService
task = TaskService.get_task("task-uuid-123")
if task:
print(f"Processing: {task['name']} pages {task['from_page']}-{task['to_page']}")
print(f"Parser: {task['parser_id']}, Language: {task['language']}")
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment