pipeline.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ) -> dict[str, Any]:
  19. return submit_pipeline_run(
  20. biz_dt=biz_dt,
  21. trigger_type="api",
  22. trigger_source=source,
  23. trigger_reason=reason,
  24. ).to_dict()
  25. def list_runs(
  26. *,
  27. limit: int,
  28. status: str | None,
  29. biz_dt: str | None,
  30. ) -> list[dict[str, Any]]:
  31. return list_pipeline_runs(limit=limit, status=status, biz_dt=biz_dt)
  32. def get_run(run_id: str) -> dict[str, Any] | None:
  33. return get_pipeline_run(run_id)
  34. def resume_run(run_id: str) -> bool:
  35. return resume_pipeline_run(run_id)
  36. def cancel_run(run_id: str) -> bool:
  37. return cancel_pipeline_run(run_id)
  38. def retry_step(run_id: str, step_key: str) -> bool:
  39. return retry_pipeline_step(run_id, step_key)
  40. def pipeline_health() -> dict[str, Any]:
  41. recent = list_pipeline_runs(limit=1)
  42. latest = recent[0] if recent else None
  43. return {
  44. "scheduler_embedded_in_api": False,
  45. "pipeline_key": "supply_pipeline",
  46. "steps": len(PIPELINE_STEPS),
  47. "latest_run": latest,
  48. **pipeline_health_snapshot(),
  49. }