refactor(scheduler): 排程迁移出web进程,迁入scheduler worker
This commit is contained in:
1 parent
970ee06537
commit
74745a9d10
21 files changed
+652
-223
No files matched your search
@@ -2,17 +2,31 @@
|
||||
backend/app/jobs/handlers/schedule_run.py
|
||||
|
||||
用途:排程任务执行 handler。
|
||||
逻辑:Wave 4 从 scheduler_service in-process 执行体迁入。
|
||||
依赖:schedule.queue_service、jobs registry/context。
|
||||
逻辑:独立 schedule worker 领取 Job 后,委托 queue_service 执行并同步双层状态。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app.jobs.context import JobContext
|
||||
from app.jobs.registry import register_handler
|
||||
from app.jobs.types import JobType
|
||||
from app.services.schedule.queue_service import execute_schedule_job
|
||||
|
||||
|
||||
@register_handler(JobType.SCHEDULE_RUN)
|
||||
def run_schedule(ctx: JobContext, payload: dict) -> None:
|
||||
"""执行单条 ScheduleTask。"""
|
||||
ctx.logger.info('schedule_run handler skeleton invoked payload=%s', payload)
|
||||
raise NotImplementedError('schedule_run handler pending Wave 4')
|
||||
"""
|
||||
执行单条已入队排程。
|
||||
|
||||
Args:
|
||||
ctx: Worker 上下文,用于日志与运行配置。
|
||||
payload: 必须包含 job_id 与 schedule_run_id。
|
||||
|
||||
Raises:
|
||||
RuntimeError: payload 缺失或执行失败时抛出,由通用 Job 层负责重试。
|
||||
"""
|
||||
job_id = int(payload.get("job_id") or 0)
|
||||
run_id = int(payload.get("schedule_run_id") or 0)
|
||||
if not job_id or not run_id:
|
||||
raise RuntimeError("job_id and schedule_run_id are required")
|
||||
execute_schedule_job(job_id=job_id, run_id=run_id, logger=ctx.logger)
|
||||
Reference in new issue
Block a user