Skip to content

Commit

Permalink
tweek
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Oct 27, 2023
1 parent be99823 commit aa9ba09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
15 changes: 13 additions & 2 deletions aggrec/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 8 additions & 19 deletions aggrec/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand All @@ -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()

Expand All @@ -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)

Expand Down

0 comments on commit aa9ba09

Please sign in to comment.