Skip to content

Commit

Permalink
Enhance server settings and fix shutdown logic
Browse files Browse the repository at this point in the history
- Removed unused thread start call in `cli.py`.
- Added `root_path` parameter in `create_app` in `main.py`.
- Enhanced type validation in `settings.py` with `TypeAdapter`.
- Updated version from 1.1.1 to 1.2.0 in `pyproject.toml`. 🚀
  • Loading branch information
horta committed Feb 11, 2025
1 parent 6a1dc57 commit bcf559d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion sched/deciphon_sched/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def main(reload: RELOAD = False):
def shutdown(server: uvicorn.Server):
if server.should_exit:
os.abort()
thread.start()
server.should_exit = True

sigint_hook(partial(shutdown, server))
Expand Down
2 changes: 1 addition & 1 deletion sched/deciphon_sched/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def lifespan(app: FastAPI):


def create_app(settings: Settings):
app = FastAPI(lifespan=lifespan)
app = FastAPI(lifespan=lifespan, root_path=settings.root_path)
app.state.settings = settings
app.state.logger = Logger(settings)

Expand Down
9 changes: 6 additions & 3 deletions sched/deciphon_sched/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

from pydantic import AnyUrl, Field, HttpUrl
from pydantic import AnyUrl, Field, HttpUrl, TypeAdapter
from pydantic_settings import BaseSettings, SettingsConfigDict

from deciphon_sched.url import http_url
Expand All @@ -25,11 +25,14 @@ class Settings(BaseSettings):
host: str = "0.0.0.0"
port: int = 8000

root_path: str = ""
endpoint_prefix: str = ""
allow_origins: list[str] = ["http://127.0.0.1", "http://localhost"]
log_level: LogLevel = Field(default="info")
log_level: LogLevel = Field(default=LogLevel.info)

database_url: AnyUrl = Field(default="sqlite+pysqlite:///:memory:")
database_url: AnyUrl = Field(
default=TypeAdapter(AnyUrl).validate_strings("sqlite+pysqlite:///:memory:")
)

s3_key: str = "minioadmin"
s3_secret: str = "minioadmin"
Expand Down
2 changes: 1 addition & 1 deletion sched/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "deciphon-sched"
version = "1.1.1"
version = "1.2.0"
description = "Deciphon scheduler"
authors = [{ name = "Danilo Horta", email = "[email protected]" }]
requires-python = "~=3.9"
Expand Down

0 comments on commit bcf559d

Please sign in to comment.