-
Notifications
You must be signed in to change notification settings - Fork 0
Code clean-up for release #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
from fastapi import Depends, FastAPI, HTTPException, Request | ||
from fastapi_utilities import repeat_at | ||
|
||
from src.config import settings | ||
|
||
from src.auth import verify_jwt | ||
from src.models import AnalyticsTxn | ||
from src.redis import set_redis_from_tx | ||
from src.redis import set_redis_from_tx, redis_count | ||
from src.database import flush | ||
|
||
|
||
app = FastAPI() | ||
app = FastAPI( | ||
title="Labs Analytics API", | ||
version="1.0.0", | ||
description="Unified Asynchronous API Engine for Penn Labs", | ||
) | ||
|
||
|
||
@app.post("/analytics/") | ||
|
@@ -17,4 +25,17 @@ async def store_data(request: Request, token: dict = Depends(verify_jwt)): | |
raise HTTPException(status_code=400, detail=str(e)) | ||
|
||
await set_redis_from_tx(txn) | ||
return {"message": "Data stored successfully!"} | ||
return {"message": "success"} | ||
|
||
|
||
@app.on_event("startup") | ||
@repeat_at(cron="0 0 * * *") | ||
async def flush_db(): | ||
count = await redis_count() | ||
print(f"{count} items found in redis") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of printing these, let's use Python's |
||
while count > 0: | ||
await flush() | ||
count -= settings.REDIS_BATCH_SIZE | ||
count = max(count, 0) | ||
print(f"{count} items left in redis") | ||
print("Redis flushed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto