"""Capture execution helper for signal source repair service.""" from __future__ import annotations from .errors import SignalSourceRepairTimeoutError from .shared import ProactiveSignalCaptureService, SignalSourceRegistry, asyncio class SignalSourceRepairCaptureMixin: """Runs capture-feishu calls with timeout protections.""" async def _capture_registry( self, *, capture_service: ProactiveSignalCaptureService, tenant_id: int, project_id: int, sender: str, row: SignalSourceRegistry, stage: str, timeout_seconds: int, ) -> dict[str, object]: message = ( self._build_explicit_repair_message(project_id=project_id, row=row) if stage == "explicit" else self._build_repair_message( project_id=project_id, registry_id=int(row.id), source_name=str(row.source_name or "信号源"), ) ) coroutine = capture_service.capture_from_feishu( group_chat_id=self._build_group_chat_id(row), message_content=message, sender=sender, tenant_id=int(tenant_id), feishu_message_id=self._build_capture_message_id( project_id=project_id, registry_id=int(row.id), stage=stage, ), ) try: return await asyncio.wait_for(coroutine, timeout=timeout_seconds) except asyncio.TimeoutError as exc: raise SignalSourceRepairTimeoutError( registry_id=int(row.id), stage=stage, timeout_seconds=timeout_seconds, ) from exc