33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""
|
|
backend/app/jobs/handlers/schedule_run.py
|
|
|
|
用途:排程任务执行 handler。
|
|
依赖: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:
|
|
"""
|
|
执行单条已入队排程。
|
|
|
|
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)
|