From ea7933793c3ca423b109df3a05c1cde44a67f757 Mon Sep 17 00:00:00 2001 From: Dmitry Afanasyev Date: Tue, 16 Aug 2022 12:34:47 +0300 Subject: [PATCH] changed to gunicorn --- app/main.py | 5 ++--- poetry.lock | 41 ++++++++++++++++++++--------------------- pyproject.toml | 2 +- scripts/start-bot.sh | 2 +- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/app/main.py b/app/main.py index dfe4eb9..b7fa17c 100644 --- a/app/main.py +++ b/app/main.py @@ -66,18 +66,17 @@ async def webhook(request: web.Request) -> web.Response: return web.Response(status=HTTPStatus.OK) -def create_app() -> web.Application: +async def create_app() -> web.Application: application = web.Application() application.router.add_post('/', webhook) return application if __name__ == '__main__': - import uvicorn if START_WITH_WEBHOOK: # bot_webhook() # type: ignore app = create_app() - uvicorn.run(app=app, host=WEBAPP_HOST, port=WEBAPP_PORT) + web.run_app(app=app, host=WEBAPP_HOST, port=WEBAPP_PORT) else: bot_polling() diff --git a/poetry.lock b/poetry.lock index 5745a51..133a8d1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -289,7 +289,7 @@ unicode_backport = ["unicodedata2"] name = "click" version = "8.1.3" description = "Composable command line interface toolkit" -category = "main" +category = "dev" optional = false python-versions = ">=3.7" @@ -650,6 +650,20 @@ python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" [package.extras] docs = ["sphinx"] +[[package]] +name = "gunicorn" +version = "20.1.0" +description = "WSGI HTTP Server for UNIX" +category = "main" +optional = false +python-versions = ">=3.5" + +[package.extras] +eventlet = ["eventlet (>=0.24.1)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +tornado = ["tornado (>=0.2)"] + [[package]] name = "h11" version = "0.12.0" @@ -1615,21 +1629,6 @@ brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"] secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] -[[package]] -name = "uvicorn" -version = "0.18.2" -description = "The lightning-fast ASGI server." -category = "main" -optional = false -python-versions = ">=3.7" - -[package.dependencies] -click = ">=7.0" -h11 = ">=0.8" - -[package.extras] -standard = ["websockets (>=10.0)", "httptools (>=0.4.0)", "watchfiles (>=0.13)", "python-dotenv (>=0.13)", "PyYAML (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "colorama (>=0.4)"] - [[package]] name = "virtualenv" version = "20.16.3" @@ -1712,7 +1711,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "ab6bb9d94e7eaa3b95756c2f584db33ba1635cca6646f9a00ef437a0142743bc" +content-hash = "afd2f88091dccff6f9285ae03e10ad29720a2d02af9cf79d33dff6c2596bcc97" [metadata.files] aiogram = [ @@ -2247,6 +2246,10 @@ greenlet = [ {file = "greenlet-1.1.2-cp39-cp39-win_amd64.whl", hash = "sha256:013d61294b6cd8fe3242932c1c5e36e5d1db2c8afb58606c5a67efce62c1f5fd"}, {file = "greenlet-1.1.2.tar.gz", hash = "sha256:e30f5ea4ae2346e62cedde8794a56858a67b878dd79f7df76a0767e356b1744a"}, ] +gunicorn = [ + {file = "gunicorn-20.1.0-py3-none-any.whl", hash = "sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e"}, + {file = "gunicorn-20.1.0.tar.gz", hash = "sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"}, +] h11 = [ {file = "h11-0.12.0-py3-none-any.whl", hash = "sha256:36a3cb8c0a032f56e2da7084577878a035d3b61d104230d4bd49c0c6b555a9c6"}, {file = "h11-0.12.0.tar.gz", hash = "sha256:47222cb6067e4a307d535814917cd98fd0a57b6788ce715755fa2b6c28b56042"}, @@ -2705,10 +2708,6 @@ urllib3 = [ {file = "urllib3-1.26.11-py2.py3-none-any.whl", hash = "sha256:c33ccba33c819596124764c23a97d25f32b28433ba0dedeb77d873a38722c9bc"}, {file = "urllib3-1.26.11.tar.gz", hash = "sha256:ea6e8fb210b19d950fab93b60c9009226c63a28808bc8386e05301e25883ac0a"}, ] -uvicorn = [ - {file = "uvicorn-0.18.2-py3-none-any.whl", hash = "sha256:c19a057deb1c5bb060946e2e5c262fc01590c6529c0af2c3d9ce941e89bc30e0"}, - {file = "uvicorn-0.18.2.tar.gz", hash = "sha256:cade07c403c397f9fe275492a48c1b869efd175d5d8a692df649e6e7e2ed8f4e"}, -] virtualenv = [ {file = "virtualenv-20.16.3-py2.py3-none-any.whl", hash = "sha256:4193b7bc8a6cd23e4eb251ac64f29b4398ab2c233531e66e40b19a6b7b0d30c1"}, {file = "virtualenv-20.16.3.tar.gz", hash = "sha256:d86ea0bb50e06252d79e6c241507cb904fcd66090c3271381372d6221a3970f9"}, diff --git a/pyproject.toml b/pyproject.toml index 59a975f..8b5f25a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ loguru = "^0.6.0" python-decouple = "^3.6" apscheduler = "^3.9.1" SQLAlchemy = {version = "^1.4", extras = ["mypy", "asyncio"]} -uvicorn = "^0.18" +gunicorn = "^20.1.0" factory-boy = "^3.2.1" Faker = "^14.0.0" diff --git a/scripts/start-bot.sh b/scripts/start-bot.sh index c55a85a..b398c1b 100644 --- a/scripts/start-bot.sh +++ b/scripts/start-bot.sh @@ -4,4 +4,4 @@ echo "starting the bot" cd /opt/mosgortrans \ && source /home/balsh/.cache/pypoetry/virtualenvs/mosgortrans-3eZxMcY3-py3.10/bin/activate \ -&& uvicorn app.main:create_app --host localhost --port 8084 --reload --factory \ No newline at end of file +&& gunicorn app.main:create_app --bind localhost:8084 --reload --worker-class aiohttp.GunicornWebWorker \ No newline at end of file