pipeline.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from __future__ import annotations
  2. from typing import Any
  3. from supply_infra.pipeline.dag import PIPELINE_STEPS
  4. from supply_infra.pipeline.health import pipeline_health_snapshot
  5. from supply_infra.pipeline.run_service import (
  6. cancel_pipeline_run,
  7. get_pipeline_run,
  8. list_pipeline_runs,
  9. resume_pipeline_run,
  10. retry_pipeline_step,
  11. submit_pipeline_run,
  12. )
  13. def create_run(
  14. *,
  15. biz_dt: str | None,
  16. source: str,
  17. reason: str | None = None,
  18. dry_run: bool = False,
  19. ) -> dict[str, Any]:
  20. return submit_pipeline_run(
  21. biz_dt=biz_dt,
  22. trigger_type="api",
  23. trigger_source=source,
  24. trigger_reason=reason,
  25. dry_run=dry_run,
  26. ).to_dict()
  27. def list_runs(
  28. *,
  29. limit: int,
  30. status: str | None,
  31. biz_dt: str | None,
  32. ) -> list[dict[str, Any]]:
  33. return list_pipeline_runs(limit=limit, status=status, biz_dt=biz_dt)
  34. def get_run(run_id: str) -> dict[str, Any] | None:
  35. return get_pipeline_run(run_id)
  36. def resume_run(run_id: str) -> bool:
  37. return resume_pipeline_run(run_id)
  38. def cancel_run(run_id: str) -> bool:
  39. return cancel_pipeline_run(run_id)
  40. def retry_step(run_id: str, step_key: str) -> bool:
  41. return retry_pipeline_step(run_id, step_key)
  42. def pipeline_health() -> dict[str, Any]:
  43. recent = list_pipeline_runs(limit=1)
  44. latest = recent[0] if recent else None
  45. return {
  46. "scheduler_embedded_in_api": False,
  47. "pipeline_key": "supply_pipeline",
  48. "steps": len(PIPELINE_STEPS),
  49. "latest_run": latest,
  50. **pipeline_health_snapshot(),
  51. }