pipeline.py 1.6 KB

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