From aa9ba09c3766a1ffe410f4938db51bd48699a855 Mon Sep 17 00:00:00 2001 From: Jakob Schlyter Date: Fri, 27 Oct 2023 07:59:08 +0200 Subject: [PATCH] tweek --- aggrec/aggregates.py | 15 +++++++++++++-- aggrec/server.py | 27 ++++++++------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/aggrec/aggregates.py b/aggrec/aggregates.py index 43428a7..f00365c 100644 --- a/aggrec/aggregates.py +++ b/aggrec/aggregates.py @@ -208,12 +208,23 @@ def get_aggregate_metadata( raise HTTPException(status.HTTP_404_NOT_FOUND) -@router.get("/api/v1/aggregates/{aggregate_id}/payload") +@router.get( + "/api/v1/aggregates/{aggregate_id}/payload", + responses={ + 200: { + "description": "Aggregate payload", + "content": { + "application/vnd.apache.parquet": {}, + "application/binary": {}, + }, + } + }, +) async def get_aggregate_payload( aggregate_id: str, settings: Annotated[Settings, Depends(get_settings)], s3_client: Annotated[aiobotocore.client.AioBaseClient, Depends(s3_client)], -): +) -> bytes: try: aggregate_object_id = ObjectId(aggregate_id) except bson.errors.InvalidId: diff --git a/aggrec/server.py b/aggrec/server.py index cc96058..5842f72 100644 --- a/aggrec/server.py +++ b/aggrec/server.py @@ -13,10 +13,8 @@ logger = logging.getLogger(__name__) -app = None - -def configure_app(config_filename: Optional[str]): +def create_settings(config_filename: Optional[str]): config_filename = config_filename or os.environ.get("AGGREC_CONFIG") if config_filename: logger.info("Reading configuration from %s", config_filename) @@ -37,10 +35,9 @@ def connect_mongodb(settings: Settings): mongoengine.connect(**params, tz_aware=True) -def create_app(config_filename: Optional[str]): +def app_factory(config_filename: Optional[str]): app = FastAPI() - - settings = configure_app(config_filename) + settings = create_settings(config_filename) @lru_cache def get_settings_override(): @@ -60,18 +57,10 @@ def main() -> None: parser = argparse.ArgumentParser(description="Aggregate Receiver") - parser.add_argument( - "--config", dest="config", metavar="filename", help="Configuration file" - ) - parser.add_argument( - "--host", dest="host", help="Host address to bind to", default="0.0.0.0" - ) - parser.add_argument( - "--port", dest="port", type=int, help="Port to listen on", default=8080 - ) - parser.add_argument( - "--debug", dest="debug", action="store_true", help="Enable debugging" - ) + parser.add_argument("--config", metavar="filename", help="Configuration file") + parser.add_argument("--host", help="Host address to bind to", default="0.0.0.0") + parser.add_argument("--port", help="Port to listen on", type=int, default=8080) + parser.add_argument("--debug", action="store_true", help="Enable debugging") args = parser.parse_args() @@ -82,7 +71,7 @@ def main() -> None: logging.basicConfig(level=logging.INFO) log_level = "info" - app = create_app(args.config) + app = app_factory(args.config) uvicorn.run(app, host=args.host, port=args.port, log_level=log_level)