Skip to content

Commit ea758ff

Browse files
author
jiangpeiling
committed
♻️ Refactor: cleanup data_process_app.py
1 parent 7fab2cd commit ea758ff

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

backend/apps/data_process_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ async def convert_state(request: ConvertStateRequest):
307307
This endpoint converts a process state string to a forward state string.
308308
"""
309309
try:
310-
result = await service.convert_celery_states_to_custom(
310+
result = service.convert_celery_states_to_custom(
311311
process_celery_state=request.process_state or "",
312312
forward_celery_state=request.forward_state or ""
313313
)

backend/consts/model.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,6 @@ class BatchTaskRequest(BaseModel):
165165
] = Field(..., description="List of source objects to process")
166166

167167

168-
class TaskResponse(BaseModel):
169-
task_id: str
170-
171-
172-
class BatchTaskResponse(BaseModel):
173-
task_ids: List[str]
174-
175-
176-
class SimpleTaskStatusResponse(BaseModel):
177-
id: str
178-
task_name: str
179-
index_name: str
180-
path_or_url: str
181-
original_filename: str
182-
status: str
183-
created_at: float
184-
updated_at: float
185-
error: Optional[str] = None
186-
187-
188-
class SimpleTasksListResponse(BaseModel):
189-
tasks: List[SimpleTaskStatusResponse]
190-
191-
192168
class IndexingResponse(BaseModel):
193169
success: bool
194170
message: str
@@ -320,11 +296,6 @@ class ConvertStateRequest(BaseModel):
320296
forward_state: str = ""
321297

322298

323-
class ConvertStateResponse(BaseModel):
324-
"""Response schema for /tasks/convert_state endpoint"""
325-
state: str
326-
327-
328299
# ---------------------------------------------------------------------------
329300
# Memory Feature Data Models (Missing previously)
330301
# ---------------------------------------------------------------------------

backend/services/data_process_service.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ async def process_uploaded_text_file(self, file_content: bytes, filename: str, c
541541
"chunking_strategy": chunking_strategy
542542
}
543543

544-
def convert_celery_states_to_custom(self, process_celery_state: str, forward_celery_state: str) -> str:
544+
def convert_celery_states_to_custom(self, process_celery_state: Optional[str], forward_celery_state: Optional[str]) -> str:
545545
"""Map Celery task states to a custom frontend state string.
546546
547547
This implements the business logic that was previously in the app layer.
@@ -554,9 +554,6 @@ def convert_celery_states_to_custom(self, process_celery_state: str, forward_cel
554554
if process_celery_state == states.SUCCESS and forward_celery_state == states.SUCCESS:
555555
return "COMPLETED"
556556

557-
if not process_celery_state and not forward_celery_state:
558-
return "WAIT_FOR_PROCESSING"
559-
560557
forward_state_map = {
561558
states.PENDING: "WAIT_FOR_FORWARDING",
562559
states.STARTED: "FORWARDING",

test/backend/services/test_data_process_service.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ def test_convert_celery_states_to_custom(self):
19921992
"PROCESSING"
19931993
)
19941994

1995-
def test_convert_celery_states_wait_for_processing(self):
1995+
async def test_convert_celery_states_wait_for_processing(self):
19961996
"""
19971997
Cover return "WAIT_FOR_PROCESSING" branches:
19981998
- both states are None
@@ -2023,6 +2023,18 @@ def test_convert_celery_states_wait_for_processing(self):
20232023
"WAIT_FOR_PROCESSING",
20242024
)
20252025

2026+
async def test_convert_celery_states_wait_for_processing_empty_strings(self):
2027+
"""
2028+
Explicitly cover the last-line default return by passing empty strings
2029+
(falsy values) for both states.
2030+
"""
2031+
self.assertEqual(
2032+
self.service.convert_celery_states_to_custom(
2033+
process_celery_state="", forward_celery_state=""
2034+
),
2035+
"WAIT_FOR_PROCESSING",
2036+
)
2037+
20262038
@pytest.mark.asyncio
20272039
async def async_test_convert_to_base64(self):
20282040
"""

0 commit comments

Comments
 (0)