stock-scraper / api /scheduler.py
sbasu2512's picture
merge the services such that we have only one entry point
c4717f1
Raw
History Blame Contribute Delete
1.77 kB
from __future__ import annotations
import os
from datetime import datetime
from zoneinfo import ZoneInfo
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
from jobs.daily_pipeline import run_pipeline
from jobs.resolve_predictions import run_resolution_job
from api.auth import require_pipeline_guid
router = APIRouter(prefix="/scheduler", tags=["scheduler"])
IST = ZoneInfo("Asia/Kolkata")
@router.get("/status")
def scheduler_status():
return {
"timezone": "Asia/Kolkata",
"scheduled_time": "16:00",
"pipeline": [
"market-data",
"prediction",
"resolution",
"metrics",
"retrain-check",
],
"current_time_ist": datetime.now(IST).isoformat(),
}
@router.post("/run-now", dependencies=[Depends(require_pipeline_guid)])
def run_now(background_tasks: BackgroundTasks):
if os.getenv("ALLOW_MANUAL_PIPELINE", "false").lower() != "true":
raise HTTPException(
status_code=403,
detail="Manual pipeline execution is disabled.",
)
background_tasks.add_task(run_pipeline)
return {
"status": "started",
"message": "Daily production pipeline queued.",
"order": [
"market-data",
"prediction",
"resolution",
"metrics",
"retrain-check",
],
}
@router.post("/resolve-now", dependencies=[Depends(require_pipeline_guid)])
def resolve_now(background_tasks: BackgroundTasks):
"""Queue the locked prediction-resolution job without running the pipeline."""
background_tasks.add_task(run_resolution_job)
return {
"status": "started",
"message": "Prediction resolution queued.",
}