Skip to content

Commit

Permalink
Call persist on summarize, add timestamp to uvicorn logger, rotate lo…
Browse files Browse the repository at this point in the history
…g file
  • Loading branch information
vladsavelyev committed Feb 23, 2024
1 parent e12aeac commit e84facc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os

import logging
from logging.handlers import RotatingFileHandler

from dotenv import load_dotenv

Expand All @@ -19,7 +20,7 @@
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[
logging.StreamHandler(),
logging.FileHandler(log_path),
RotatingFileHandler(log_path, maxBytes=10_000, backupCount=10),
],
)
logging.debug(f"Logging to {log_path}")
7 changes: 7 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

logger = logging.getLogger(__name__)


app = FastAPI(
title="MultiQC API",
description="MultiQC API service, providing run-time information about available updates.",
Expand Down Expand Up @@ -58,6 +59,10 @@ def get_latest_release() -> models.LatestRelease:

@app.on_event("startup")
async def startup():
# Add timestamp to the uvicorn logger
logger = logging.getLogger("uvicorn.access")
for h in logger.handlers:
h.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
# Initialise the DB and tables on server startup
db.create_db_and_tables()
# Sync latest version tag using GitHub API
Expand Down Expand Up @@ -201,6 +206,7 @@ def _summarize_visits(interval="5min") -> Response:
"""
Summarize visits from the CSV file and write to the database
"""
_persist_visits()
global visit_buffer_lock
with visit_buffer_lock:
if not CSV_FILE_PATH.exists():
Expand Down Expand Up @@ -338,6 +344,7 @@ async def update_downloads_endpoint(background_tasks: BackgroundTasks):


if os.getenv("ENVIRONMENT") == "DEV":

@app.post("/clean_visits_csv_file")
async def clean_visits_csv_file():
try:
Expand Down

0 comments on commit e84facc

Please sign in to comment.