Skip to content

Commit

Permalink
v0.2.0 - Hypercorn ASGI (#36)
Browse files Browse the repository at this point in the history
* simplified log output

* set root log level to debug. disabled sql engine echo

* updated gitignore

* Hypercorn (#35)

* runs w gunicorn

* updated starter script

* uvicorn logs now collected in uvicorn.log file

* added log conf

* added host option

* misc updates

* hypercorn implementation works yay

* logs shoowing up in /tmp

* updated log conf

* now logs to files in local dir

* removed guincorn start script and renamed other script to start_app

* updated deps
  • Loading branch information
fullerzz authored Jul 17, 2024
1 parent d6d5bf7 commit b984b67
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 487 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down Expand Up @@ -169,6 +169,7 @@ cython_debug/
scripts/*
!scripts/start_dev.sh
!scripts/test.sh
!scripts/start_app.sh

# local file cache
uploads/*
Expand Down
48 changes: 48 additions & 0 deletions logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[loggers]
keys=root, hypercorn.error, hypercorn.access

[handlers]
keys=console, error_file, access_file

[formatters]
keys=generic, access

[logger_root]
level=DEBUG
handlers=console

[logger_hypercorn.error]
level=INFO
handlers=error_file
propagate=1
qualname=hypercorn.error

[logger_hypercorn.access]
level=DEBUG
handlers=access_file
propagate=0
qualname=hypercorn.access

[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )

[handler_error_file]
class=logging.FileHandler
formatter=generic
args=('hypercorn.error.log',)

[handler_access_file]
class=logging.FileHandler
formatter=access
args=('hypercorn.access.log',)

[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter

[formatter_access]
format=%(message)s
class=logging.Formatter
599 changes: 261 additions & 338 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ fastapi = "^0.111.0"
sqlmodel = "^0.0.19"
rich = "^13.7.1"
python-multipart = "^0.0.9"
beartype = "^0.18.5"
python-dotenv = "^1.0.1"
pydantic-settings = "^2.3.4"

hypercorn = "^0.17.3"

[tool.poetry.group.dev.dependencies]
boto3-stubs = {extras = ["essential"], version = "^1.34.136"}
Expand All @@ -28,7 +27,6 @@ pytest = "^8.2.2"
pytest-asyncio = "^0.23.7"
moto = {extras = ["all"], version = "^5.0.10"}


[tool.ruff]
line-length = 120
indent-width = 4
Expand Down
158 changes: 21 additions & 137 deletions requirements.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions scripts/start_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

poetry run hypercorn src.smolvault.main:app -b 0.0.0.0 --debug --log-config=logging.conf --log-level=DEBUG --access-logfile=hypercorn.access.log --error-logfile=hypercorn.error.log --keep-alive=120 --workers=1
3 changes: 0 additions & 3 deletions scripts/start_dev.sh

This file was deleted.

3 changes: 0 additions & 3 deletions src/smolvault/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from beartype.claw import beartype_this_package # <-- this is boring, but...

beartype_this_package() # <-- the fast way
2 changes: 1 addition & 1 deletion src/smolvault/clients/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FileTag(SQLModel, table=True):
class DatabaseClient:
def __init__(self) -> None:
self.settings = get_settings()
self.engine = create_engine(f"sqlite:///{self.settings.smolvault_db}", echo=True)
self.engine = create_engine(f"sqlite:///{self.settings.smolvault_db}", echo=False)
SQLModel.metadata.create_all(self.engine)

def add_metadata(self, file_upload: FileUploadDTO, key: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/smolvault/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
logging.basicConfig(
handlers=[RotatingFileHandler("app.log", maxBytes=100_000, backupCount=10), logging.StreamHandler(sys.stdout)],
level=logging.INFO,
format="%(asctime)s [%(processName)s: %(process)d] [%(threadName)s: %(thread)d] [%(levelname)s] %(name)s: %(message)s",
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)

Expand Down

0 comments on commit b984b67

Please sign in to comment.