scheduler.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Compatibility facade over the durable pipeline control plane."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from api.services.pipeline import get_run, pipeline_health
  5. from supply_infra.config import get_infra_settings
  6. from supply_infra.pipeline.dag import PIPELINE_STEPS
  7. from supply_infra.pipeline.dates import CHINA_TIMEZONE, next_schedule_china
  8. from supply_infra.pipeline.run_service import submit_pipeline_run
  9. from supply_infra.scheduler.constants import SUPPLY_PIPELINE_JOB_ID, SUPPLY_PIPELINE_JOB_NAME
  10. def list_triggerable_jobs() -> list[dict[str, Any]]:
  11. return [
  12. {
  13. "id": SUPPLY_PIPELINE_JOB_ID,
  14. "name": SUPPLY_PIPELINE_JOB_NAME,
  15. "description": "提交严格门禁的 12 步持久化供给流水线",
  16. "accepts_biz_dt": True,
  17. "deprecated": False,
  18. "steps": [step.key for step in PIPELINE_STEPS],
  19. }
  20. ]
  21. def run_scheduler_job(
  22. job_id: str,
  23. *,
  24. biz_dt: str | None = None,
  25. ) -> dict[str, Any]:
  26. if job_id != SUPPLY_PIPELINE_JOB_ID:
  27. raise KeyError(job_id)
  28. return submit_pipeline_run(
  29. biz_dt=biz_dt,
  30. trigger_type="api",
  31. trigger_source="legacy_scheduler_api",
  32. ).to_dict()
  33. def get_scheduler_job_run(run_id: str) -> dict[str, Any] | None:
  34. return get_run(run_id)
  35. def run_supply_pipeline(*, biz_dt: str | None = None) -> dict[str, Any]:
  36. return run_scheduler_job(SUPPLY_PIPELINE_JOB_ID, biz_dt=biz_dt)
  37. def scheduler_status() -> dict[str, Any]:
  38. settings = get_infra_settings()
  39. health = pipeline_health()
  40. return {
  41. "enabled": settings.scheduler_enabled,
  42. "running": health["scheduler_running"],
  43. "embedded": False,
  44. "deprecated": True,
  45. "timezone": settings.scheduler_timezone,
  46. "jobs": [
  47. {
  48. "id": SUPPLY_PIPELINE_JOB_ID,
  49. "name": SUPPLY_PIPELINE_JOB_NAME,
  50. "next_run_time": next_schedule_china(settings=settings)
  51. .replace(tzinfo=CHINA_TIMEZONE)
  52. .isoformat(),
  53. }
  54. ],
  55. **health,
  56. }