2026-02-26 23:55:47 +05:30
|
|
|
"""Task dispatcher abstraction for background document processing.
|
|
|
|
|
|
|
|
|
|
Decouples the upload endpoint from Celery so tests can swap in a
|
|
|
|
|
synchronous (inline) implementation that needs only PostgreSQL.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import Protocol
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TaskDispatcher(Protocol):
|
|
|
|
|
async def dispatch_file_processing(
|
|
|
|
|
self,
|
|
|
|
|
*,
|
|
|
|
|
document_id: int,
|
|
|
|
|
temp_path: str,
|
|
|
|
|
filename: str,
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
workspace_id: int,
|
2026-02-26 23:55:47 +05:30
|
|
|
user_id: str,
|
2026-04-10 16:45:51 +02:00
|
|
|
use_vision_llm: bool = False,
|
2026-04-14 21:26:00 -07:00
|
|
|
processing_mode: str = "basic",
|
2026-02-26 23:55:47 +05:30
|
|
|
) -> None: ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CeleryTaskDispatcher:
|
|
|
|
|
"""Production dispatcher — fires Celery tasks via Redis broker."""
|
|
|
|
|
|
|
|
|
|
async def dispatch_file_processing(
|
|
|
|
|
self,
|
|
|
|
|
*,
|
|
|
|
|
document_id: int,
|
|
|
|
|
temp_path: str,
|
|
|
|
|
filename: str,
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
workspace_id: int,
|
2026-02-26 23:55:47 +05:30
|
|
|
user_id: str,
|
2026-04-10 16:45:51 +02:00
|
|
|
use_vision_llm: bool = False,
|
2026-04-14 21:26:00 -07:00
|
|
|
processing_mode: str = "basic",
|
2026-02-26 23:55:47 +05:30
|
|
|
) -> None:
|
|
|
|
|
from app.tasks.celery_tasks.document_tasks import (
|
|
|
|
|
process_file_upload_with_document_task,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
process_file_upload_with_document_task.delay(
|
|
|
|
|
document_id=document_id,
|
|
|
|
|
temp_path=temp_path,
|
|
|
|
|
filename=filename,
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
workspace_id=workspace_id,
|
2026-02-26 23:55:47 +05:30
|
|
|
user_id=user_id,
|
2026-04-10 16:45:51 +02:00
|
|
|
use_vision_llm=use_vision_llm,
|
2026-04-14 21:26:00 -07:00
|
|
|
processing_mode=processing_mode,
|
2026-02-26 23:55:47 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_task_dispatcher() -> TaskDispatcher:
|
|
|
|
|
return CeleryTaskDispatcher()
|