repository.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """Repository contracts for formal pipeline state."""
  2. from __future__ import annotations
  3. from typing import Any, Protocol
  4. from uuid import UUID
  5. from pipeline.models import PipelineJob, PipelineRun, PipelineStage, ResumeCursor
  6. class PipelineRepository(Protocol):
  7. """Persistence boundary for orchestration and resumable jobs.
  8. The first migration does not create dedicated pipeline tables yet, so this
  9. interface captures the intended boundary before a persistence decision.
  10. """
  11. def create_pipeline_run(
  12. self,
  13. *,
  14. run_key: str | None = None,
  15. batch_id: UUID | None = None,
  16. status: str = "pending",
  17. metadata: dict[str, Any] | None = None,
  18. ) -> PipelineRun:
  19. ...
  20. def get_pipeline_run(self, run_id: UUID) -> PipelineRun:
  21. ...
  22. def save_pipeline_job(
  23. self,
  24. *,
  25. run_id: UUID,
  26. stage: PipelineStage,
  27. target_id: UUID | None = None,
  28. status: str = "pending",
  29. metadata: dict[str, Any] | None = None,
  30. ) -> PipelineJob:
  31. ...
  32. def mark_job_status(
  33. self,
  34. job_id: UUID,
  35. *,
  36. status: str,
  37. error_message: str | None = None,
  38. metadata: dict[str, Any] | None = None,
  39. ) -> PipelineJob:
  40. ...
  41. def get_resume_cursor(self, run_id: UUID) -> ResumeCursor | None:
  42. ...