diff --git a/requirements.txt b/requirements.txt index 19c3e84..2af8dc3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,24 @@ aiohappyeyeballs==2.3.4 aiohttp==3.10.0 aiosignal==1.3.1 +asgiref==3.8.1 attrs==23.2.0 blinker==1.8.2 click==8.1.7 Flask==3.0.3 frozenlist==1.4.1 +h11==0.14.0 +h2==4.1.0 +hpack==4.0.0 +Hypercorn==0.17.3 +hyperframe==6.0.1 idna==3.7 itsdangerous==2.2.0 Jinja2==3.1.4 MarkupSafe==2.1.5 multidict==6.0.5 +priority==2.0.0 +waitress==3.0.0 Werkzeug==3.0.3 +wsproto==1.2.0 yarl==1.9.4 diff --git a/src/main.py b/src/main.py index ef11c5e..97fff07 100644 --- a/src/main.py +++ b/src/main.py @@ -73,15 +73,18 @@ async def fetch_artifact(artifact_url): data = await response.read() return data +async def handle_artifact(artifact_name: str): + task = await fetch_tasks() + artifact_url = f"{task}/artifacts/{artifact_name}" + artifact_data = await fetch_artifact(artifact_url) + response = Response(artifact_data) + response.headers['Content-Disposition'] = f'attachment; filename="{artifact_name}.zip"' + return response + def create_handle_artifact(artifact_name: str): - def handle_artifact(): - task = asyncio.run(fetch_tasks()) - artifact_url = f"{task}/artifacts/{artifact_name}" - artifact_data = asyncio.run(fetch_artifact(artifact_url)) - response = Response(artifact_data) - response.headers['Content-Disposition'] = 'attachment; filename="GalacticFactory.zip"' - return response - return handle_artifact + async def handle_artifact_async(): + return await handle_artifact(artifact_name) + return handle_artifact_async for artifact_name in config.artifact_names: route = f'/{artifact_name}' @@ -95,4 +98,8 @@ def handle_sigterm(*args): signal.signal(signal.SIGTERM, handle_sigterm) if __name__ == '__main__': - app.run(debug=config.debug, host='0.0.0.0', port=80) + from hypercorn.asyncio import serve + from hypercorn.config import Config as HypercornConfig + h_config = HypercornConfig() + h_config.bind = ["0.0.0.0:80"] + asyncio.run(serve(app=app, config=h_config))