Spaces:
Sleeping
Sleeping
File size: 879 Bytes
cbe9ae7 468806c cbe9ae7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | from fastapi import APIRouter, HTTPException
from fastapi.responses import JSONResponse
from services.erp_sync_job_service import get_sync_status, trigger_sync
router = APIRouter()
@router.post("/sync/trigger", tags=["erp-sync"])
def trigger_erp_sync():
result = trigger_sync()
if not result["started"]:
raise HTTPException(
status_code=409,
detail={
"message": "Sync already running.",
"started_at": result.get("started_at"),
},
)
return JSONResponse(
status_code=202,
content={
"message": "Sync started in background.",
"started_at": result["started_at"],
"note": "Poll /sync/status to monitor progress.",
},
)
@router.get("/sync/status", tags=["erp-sync"])
def erp_sync_status():
return get_sync_status()
|