From bcf559dc4d949f1a886c9aac0f3e5b0c6a61f434 Mon Sep 17 00:00:00 2001 From: Danilo Horta Date: Tue, 11 Feb 2025 11:18:53 +0000 Subject: [PATCH] Enhance server settings and fix shutdown logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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`. 🚀 --- sched/deciphon_sched/cli.py | 1 - sched/deciphon_sched/main.py | 2 +- sched/deciphon_sched/settings.py | 9 ++++++--- sched/pyproject.toml | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sched/deciphon_sched/cli.py b/sched/deciphon_sched/cli.py index 73e1594..4a7cad1 100644 --- a/sched/deciphon_sched/cli.py +++ b/sched/deciphon_sched/cli.py @@ -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)) diff --git a/sched/deciphon_sched/main.py b/sched/deciphon_sched/main.py index 57fc9fc..a0896a2 100644 --- a/sched/deciphon_sched/main.py +++ b/sched/deciphon_sched/main.py @@ -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) diff --git a/sched/deciphon_sched/settings.py b/sched/deciphon_sched/settings.py index be8ad0f..ceb6f78 100644 --- a/sched/deciphon_sched/settings.py +++ b/sched/deciphon_sched/settings.py @@ -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 @@ -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" diff --git a/sched/pyproject.toml b/sched/pyproject.toml index 60cf143..8d6d9bd 100644 --- a/sched/pyproject.toml +++ b/sched/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "deciphon-sched" -version = "1.1.1" +version = "1.2.0" description = "Deciphon scheduler" authors = [{ name = "Danilo Horta", email = "horta@ebi.ac.uk" }] requires-python = "~=3.9"