|
import os |
|
from datetime import datetime |
|
from fastapi import APIRouter |
|
|
|
from ... import config as app_config |
|
|
|
router = APIRouter() |
|
|
|
|
|
@router.get("/status") |
|
def is_running(): |
|
"""Return a small status dict: whether pipeline appears to be running and last run time.""" |
|
json_folder = os.path.join(app_config.DATA_DIR, 'merged', 'features') |
|
has_json = False |
|
if os.path.exists(json_folder): |
|
try: |
|
has_json = any(f.endswith('.json') for f in os.listdir(json_folder)) |
|
except Exception: |
|
has_json = False |
|
|
|
last_run_file = app_config.LAST_RUN_PATH |
|
last_run_display = 'Unknown' |
|
try: |
|
if os.path.exists(last_run_file): |
|
with open(last_run_file, 'r') as f: |
|
last_run_str = f.read().strip() |
|
last_run_dt = datetime.strptime(last_run_str, '%Y-%m-%d %H:%M:%S') |
|
minutes_ago = int((datetime.now() - last_run_dt).total_seconds() // 60) |
|
last_run_display = f"{minutes_ago} minutes ago" |
|
except Exception: |
|
last_run_display = 'Unknown' |
|
|
|
status = "Running" if not has_json else "Not Running" |
|
return {"status": status, "last_run": last_run_display} |