Skip to content

Commit

Permalink
Add visit in a background task to avoid waiting on lock
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsavelyev committed Feb 21, 2024
1 parent 380e6ac commit 7412dfe
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def update_version():

@app.get("/version") # log a visit
async def version(
background_tasks: BackgroundTasks,
version_multiqc: str = "",
version_python: str = "",
operating_system: str = "",
Expand All @@ -104,6 +105,24 @@ async def version(
Endpoint for MultiQC that returns the latest release, and logs
the visit along with basic user environment detail.
"""
background_tasks.add_task(
_log_visit,
version_multiqc=version_multiqc,
version_python=version_python,
operating_system=operating_system,
installation_method=installation_method,
ci_environment=ci_environment,
)
return models.VersionResponse(latest_release=app.latest_release)


def _log_visit(
version_multiqc: str = "",
version_python: str = "",
operating_system: str = "",
installation_method: str = "",
ci_environment: str = "",
):
global visit_buffer
with visit_buffer_lock:
visit_buffer.append(
Expand All @@ -116,8 +135,7 @@ async def version(
"ci_environment": ci_environment,
}
)
logger.info(f"Logging visit, total visits: {len(visit_buffer)}")
return models.VersionResponse(latest_release=app.latest_release)
logger.info(f"Logging visit, total visits: {len(visit_buffer)}")


# Path to a buffer CSV file to persist recent visits before dumping to the database
Expand Down

0 comments on commit 7412dfe

Please sign in to comment.