Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
notatallshaw committed Nov 4, 2024
1 parent f515e42 commit a85f311
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies = [
"packaging>=24.1",
"typer>=0.12.5",
"uvicorn>=0.32.0",
"uvloop>=0.21.0",
"werkzeug>=3.0.4",
"whenever~=0.6.9",
]
Expand All @@ -31,4 +32,4 @@ dev-dependencies = [
]

[tool.ruff.lint]
extend-select = ["I"]
extend-select = ["I"]
6 changes: 5 additions & 1 deletion src/pip_timemachine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ def filter_files_by_moment(files: list[dict]) -> tuple[list, dict]:
modified_versions[version] = None
return modified_files, modified_versions


def initiate_shutdown():
logger.info("Gracefully shutting down")
if UNICORN_SERVER:
UNICORN_SERVER.should_exit = True


@app.get("/shutdown-pip-timemachine-server")
async def shutdown_pip_timemachine_server(background_tasks: BackgroundTasks):
"""
Expand Down Expand Up @@ -145,7 +147,9 @@ def run_server(moment: dt.datetime, index: str = INDEX, port: int = 8040):
INDEX = index.rstrip("/")

UNICORN_SERVER = uvicorn.Server(
uvicorn.Config("pip_timemachine.main:app", port=port)
uvicorn.Config(
"pip_timemachine.main:app", port=port, workers=4, timeout_keep_alive=15
)
)
UNICORN_SERVER.run()

Expand Down
34 changes: 34 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a85f311

Please sign in to comment.