Added periodic fetch
This commit is contained in:
@@ -10,8 +10,7 @@ from models.event_model import normalize_event
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/fetch-audit-logs")
|
||||
def fetch_logs(hours: int = 168):
|
||||
def run_fetch(hours: int = 168):
|
||||
window = max(1, min(hours, 720)) # cap to 30 days for sanity
|
||||
logs = []
|
||||
errors = []
|
||||
@@ -38,3 +37,11 @@ def fetch_logs(hours: int = 168):
|
||||
ops.append(UpdateOne({"id": doc.get("id"), "timestamp": doc.get("timestamp")}, {"$set": doc}, upsert=True))
|
||||
events_collection.bulk_write(ops, ordered=False)
|
||||
return {"stored_events": len(normalized), "errors": errors}
|
||||
|
||||
|
||||
@router.get("/fetch-audit-logs")
|
||||
def fetch_logs(hours: int = 168):
|
||||
try:
|
||||
return run_fetch(hours=hours)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||
|
||||
Reference in New Issue
Block a user