Spaces:
Running
Running
| 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") | |
| 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(), | |
| } | |
| 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", | |
| ], | |
| } | |
| 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.", | |
| } | |