scheduler.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "accepts_partition_date": False,
  18. "deprecated": False,
  19. "steps": [step.key for step in PIPELINE_STEPS],
  20. }
  21. ]
  22. def run_scheduler_job(
  23. job_id: str,
  24. *,
  25. biz_dt: str | None = None,
  26. partition_date: str | None = None,
  27. wait: bool = False,
  28. ) -> dict[str, Any]:
  29. del partition_date
  30. if job_id != SUPPLY_PIPELINE_JOB_ID:
  31. raise KeyError(job_id)
  32. if wait:
  33. raise ValueError("wait=true is disabled for the durable API; poll by run_id")
  34. return submit_pipeline_run(
  35. biz_dt=biz_dt,
  36. trigger_type="api",
  37. trigger_source="legacy_scheduler_api",
  38. ).to_dict()
  39. def get_scheduler_job_run(run_id: str) -> dict[str, Any] | None:
  40. return get_run(run_id)
  41. def run_supply_pipeline(*, biz_dt: str | None = None) -> dict[str, Any]:
  42. return run_scheduler_job(SUPPLY_PIPELINE_JOB_ID, biz_dt=biz_dt)
  43. def scheduler_status() -> dict[str, Any]:
  44. settings = get_infra_settings()
  45. health = pipeline_health()
  46. return {
  47. "enabled": settings.scheduler_enabled,
  48. "running": health["scheduler_running"],
  49. "embedded": False,
  50. "deprecated": True,
  51. "timezone": settings.scheduler_timezone,
  52. "jobs": [
  53. {
  54. "id": SUPPLY_PIPELINE_JOB_ID,
  55. "name": SUPPLY_PIPELINE_JOB_NAME,
  56. "next_run_time": next_schedule_china(settings=settings)
  57. .replace(tzinfo=CHINA_TIMEZONE)
  58. .isoformat(),
  59. }
  60. ],
  61. **health,
  62. }