30 lines
777 B
Python
30 lines
777 B
Python
from fastapi import APIRouter
|
|
from app.scheduler.jobs import scheduler
|
|
from app.models.schemas import JobResponse
|
|
|
|
router = APIRouter(prefix="/scheduler", tags=["scheduler"])
|
|
|
|
|
|
@router.get("/jobs")
|
|
async def list_jobs():
|
|
jobs = []
|
|
for job in scheduler.get_jobs():
|
|
jobs.append(JobResponse(
|
|
id=job.id,
|
|
name=job.name,
|
|
next_run_time=str(job.next_run_time) if job.next_run_time else None,
|
|
))
|
|
return {"jobs": jobs}
|
|
|
|
|
|
@router.post("/pause/{job_id}")
|
|
async def pause_job(job_id: str):
|
|
scheduler.pause_job(job_id)
|
|
return {"status": "paused", "job_id": job_id}
|
|
|
|
|
|
@router.post("/resume/{job_id}")
|
|
async def resume_job(job_id: str):
|
|
scheduler.resume_job(job_id)
|
|
return {"status": "resumed", "job_id": job_id}
|