registry.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from __future__ import annotations
  2. from collections.abc import Callable
  3. from typing import Any
  4. from supply_infra.pipeline.contracts import StepContext
  5. StepHandler = Callable[[StepContext], dict[str, Any]]
  6. def _global_tree(context: StepContext) -> dict[str, Any]:
  7. from supply_infra.scheduler.jobs.sync_global_tree_odps_to_mysql import (
  8. sync_global_tree_odps_to_mysql,
  9. )
  10. return sync_global_tree_odps_to_mysql(
  11. partition_date=str(context.date_snapshot["global_tree_partition"])
  12. )
  13. def _demand_source(context: StepContext) -> dict[str, Any]:
  14. from supply_infra.scheduler.jobs.demand_pool.sync import _sync_pool_rows
  15. return _sync_pool_rows(str(context.date_snapshot["demand_pool_partition"]))
  16. def _demand_classify(context: StepContext) -> dict[str, Any]:
  17. from supply_infra.scheduler.jobs.demand_pool.sync import _classify_words
  18. return _classify_words(context.biz_dt)
  19. def _demand_rel(context: StepContext) -> dict[str, Any]:
  20. from supply_infra.scheduler.jobs.demand_pool.belong_rel import (
  21. sync_demand_belong_pool_rel,
  22. )
  23. return sync_demand_belong_pool_rel(
  24. str(context.date_snapshot["demand_pool_partition"])
  25. )
  26. def _real_metrics(context: StepContext) -> dict[str, Any]:
  27. from supply_infra.scheduler.jobs.demand_pool.sync import enrich_real_rov_vov_7d
  28. return enrich_real_rov_vov_7d(context.biz_dt)
  29. def _popularity(context: StepContext) -> dict[str, Any]:
  30. from supply_infra.scheduler.jobs.demand_pool.sync import compute_popularity_stats
  31. return compute_popularity_stats(context.biz_dt)
  32. def _tree_weight(context: StepContext) -> dict[str, Any]:
  33. from supply_infra.scheduler.jobs.demand_pool.tree_weight import (
  34. compute_category_tree_weight,
  35. )
  36. return compute_category_tree_weight(context.biz_dt)
  37. def _source_videos(context: StepContext) -> dict[str, Any]:
  38. from supply_infra.scheduler.jobs.demand_pool.videos import sync_multi_demand_videos
  39. return sync_multi_demand_videos(
  40. limit=None,
  41. decode_dt=str(context.date_snapshot["video_decode_partition"]),
  42. )
  43. def _grade(context: StepContext) -> dict[str, Any]:
  44. from supply_infra.scheduler.jobs.grade_demand_pool import grade_demand_pool
  45. return grade_demand_pool(context.biz_dt)
  46. def _platform_demand_materialize(context: StepContext) -> dict[str, Any]:
  47. from supply_infra.business_harness.materialize import (
  48. materialize_platform_demands,
  49. )
  50. return materialize_platform_demands(context)
  51. def _daily_demand_package(context: StepContext) -> dict[str, Any]:
  52. from supply_infra.business_harness.evaluate import (
  53. publish_daily_demand_package,
  54. )
  55. return publish_daily_demand_package(context)
  56. def _expand(context: StepContext) -> dict[str, Any]:
  57. from supply_infra.scheduler.jobs.expand_demand_from_video_points import (
  58. expand_demand_from_video_points,
  59. )
  60. return expand_demand_from_video_points(
  61. context.biz_dt,
  62. workers=5,
  63. )
  64. def _discover(context: StepContext) -> dict[str, Any]:
  65. from supply_infra.scheduler.constants import PIPELINE_FIND_AGENT_WORKERS
  66. from supply_infra.scheduler.jobs.discover_videos_from_demands import (
  67. discover_videos_from_demands,
  68. )
  69. return discover_videos_from_demands(
  70. context.biz_dt,
  71. workers=PIPELINE_FIND_AGENT_WORKERS,
  72. package_run_id=context.run_id,
  73. )
  74. def _content_feedback(context: StepContext) -> dict[str, Any]:
  75. from supply_infra.business_harness.content_feedback import (
  76. materialize_content_feedback,
  77. )
  78. return materialize_content_feedback(context)
  79. def _aigc_write_record(context: StepContext) -> dict[str, Any]:
  80. from supply_infra.pipeline.aigc_outbox import execute_aigc_outbox
  81. return execute_aigc_outbox(context)
  82. STEP_REGISTRY: dict[str, StepHandler] = {
  83. "global_tree_sync": _global_tree,
  84. "demand_pool_source_sync": _demand_source,
  85. "demand_classify": _demand_classify,
  86. "demand_belong_rel_sync": _demand_rel,
  87. "real_metrics_sync": _real_metrics,
  88. "popularity_stats": _popularity,
  89. "category_tree_weight": _tree_weight,
  90. "source_video_sync": _source_videos,
  91. "demand_grade": _grade,
  92. "platform_demand_materialize": _platform_demand_materialize,
  93. "daily_demand_package": _daily_demand_package,
  94. "demand_expand": _expand,
  95. "video_discovery": _discover,
  96. "content_feedback_materialize": _content_feedback,
  97. "aigc_write_record": _aigc_write_record,
  98. }
  99. def execute_registered_step(context: StepContext) -> dict[str, Any]:
  100. handler = STEP_REGISTRY.get(context.step_key)
  101. if handler is None:
  102. raise KeyError(f"Unknown pipeline step: {context.step_key}")
  103. payload = handler(context)
  104. if not isinstance(payload, dict):
  105. return {"success": True, "result": payload}
  106. return payload