From 73d0452a84e6741ecefeaf9fb8432a9d07658a05 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Tue, 6 Jun 2023 12:08:21 +0100 Subject: [PATCH 01/10] upgrade sqlalchem --- tcsocket/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcsocket/requirements.txt b/tcsocket/requirements.txt index 631165e..1099af7 100644 --- a/tcsocket/requirements.txt +++ b/tcsocket/requirements.txt @@ -1,4 +1,4 @@ -SQLAlchemy==1.4.40 +SQLAlchemy==2.0.12 aiodns==3.0.0 aiohttp==3.8.1 aiopg==1.3.4 From f6fbfc9d248c06a902037ad4d7333676a459ada3 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Tue, 6 Jun 2023 12:15:38 +0100 Subject: [PATCH 02/10] upgrade aiopg --- tcsocket/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcsocket/requirements.txt b/tcsocket/requirements.txt index 1099af7..1d1cf9f 100644 --- a/tcsocket/requirements.txt +++ b/tcsocket/requirements.txt @@ -1,7 +1,7 @@ SQLAlchemy==2.0.12 aiodns==3.0.0 aiohttp==3.8.1 -aiopg==1.3.4 +aiopg==1.4.0 aioredis==1.3.1 arq==0.22 boto3==1.24.57 From ef2ebce967e71846001d46465cabd1206860c305 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Tue, 6 Jun 2023 12:32:08 +0100 Subject: [PATCH 03/10] change to postgresql:// --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f66966..aebf284 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: options: --entrypoint redis-server env: - DATABASE_URL: 'postgres://postgres:postgres@127.0.0.1:5432/socket_test' + DATABASE_URL: 'postgresql://postgres:postgres@127.0.0.1:5432/socket_test' steps: - uses: actions/checkout@v2 From f0db3da5756a731acfb48a5fe8bb06e4a0913870 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Wed, 28 Jun 2023 16:11:19 +0100 Subject: [PATCH 04/10] update gh action --- .github/workflows/main.yml | 6 +++--- tests/conftest.py | 3 ++- tests/requirements.txt | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aebf284..0f5ddf0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,10 +32,10 @@ jobs: DATABASE_URL: 'postgresql://postgres:postgres@127.0.0.1:5432/socket_test' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: set up python - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: '3.8' @@ -68,7 +68,7 @@ jobs: HEROKU_APP: tc-socket steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: git fetch --unshallow - run: git switch master - run: git remote add heroku https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP.git diff --git a/tests/conftest.py b/tests/conftest.py index 9c9c2a8..5202323 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ from time import time import pytest +import asyncio from aiohttp import ClientSession, ClientTimeout from aiohttp.web import Application, Response, json_response from aiopg.sa import create_engine as aio_create_engine @@ -27,7 +28,7 @@ MASTER_KEY = 'this is the master key' DB_DSN = 'postgresql://postgres@localhost:5432/socket_test' - +asyncio_mode = "auto" async def test_image_view(request): image_format = request.query.get('format') diff --git a/tests/requirements.txt b/tests/requirements.txt index 223a43b..d7c4ea4 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -7,7 +7,7 @@ pycodestyle==2.9.1 pyflakes==2.5.0 pytest==7.1.2 pytest-aiohttp==1.0.4 -pytest-asyncio==0.18.3 +pytest-asyncio==0.21.0 pytest-cov==3.0.0 pytest-isort==3.0.0 pytest-mock==3.8.2 From 48e65b46ab73076aebcb6edcf00c5245557ea6f0 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Wed, 28 Jun 2023 16:20:51 +0100 Subject: [PATCH 05/10] no asyncio --- tests/conftest.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5202323..4883a30 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ from time import time import pytest -import asyncio from aiohttp import ClientSession, ClientTimeout from aiohttp.web import Application, Response, json_response from aiopg.sa import create_engine as aio_create_engine @@ -28,7 +27,6 @@ MASTER_KEY = 'this is the master key' DB_DSN = 'postgresql://postgres@localhost:5432/socket_test' -asyncio_mode = "auto" async def test_image_view(request): image_format = request.query.get('format') From 3246723b305ddb22dc98767242b394d85faf2c94 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Wed, 28 Jun 2023 16:25:55 +0100 Subject: [PATCH 06/10] lint --- tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/conftest.py b/tests/conftest.py index 4883a30..9c9c2a8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,6 +28,7 @@ MASTER_KEY = 'this is the master key' DB_DSN = 'postgresql://postgres@localhost:5432/socket_test' + async def test_image_view(request): image_format = request.query.get('format') stream = BytesIO() From beee2649851c2bd3bcef8823f5110dcddd4e0d1b Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Wed, 28 Jun 2023 17:08:42 +0100 Subject: [PATCH 07/10] upgraded sqlalchemy --- tcsocket/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tcsocket/requirements.txt b/tcsocket/requirements.txt index 1d1cf9f..9d37f04 100644 --- a/tcsocket/requirements.txt +++ b/tcsocket/requirements.txt @@ -1,7 +1,7 @@ -SQLAlchemy==2.0.12 +sqlalchemy==1.4.38 aiodns==3.0.0 aiohttp==3.8.1 -aiopg==1.4.0 +aiopg==1.3.4 aioredis==1.3.1 arq==0.22 boto3==1.24.57 From 379c9a24e44c4459ba723aa8ec2a4e78f2285dc5 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Wed, 28 Jun 2023 17:30:25 +0100 Subject: [PATCH 08/10] start_stop + solve event loop --- tcsocket/run.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tcsocket/run.py b/tcsocket/run.py index d5f30a4..3d4d46e 100755 --- a/tcsocket/run.py +++ b/tcsocket/run.py @@ -4,6 +4,8 @@ from functools import partial import click +from pytest_asyncio.plugin import event_loop + from app.logs import setup_logging from app.main import create_app from app.management import prepare_database, run_patch @@ -24,17 +26,20 @@ def cli(verbose): setup_logging(verbose) +async def start_and_stop_app(app): + await app.startup() + await app.cleanup() + def check_app(): - loop = asyncio.get_event_loop() logger.info("initialising aiohttp app to check it's working...") - app = create_app(loop) + app = create_app() app.freeze() - loop.run_until_complete(app.startup()) - loop.run_until_complete(app.cleanup()) + asyncio.run(start_and_stop_app(app)) del app logger.info('app started and stopped successfully, apparently configured correctly') + def web(): """ Serve the application From 254a1cc29afb37aaf0acc453bf90d69de1178d69 Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Wed, 28 Jun 2023 17:47:45 +0100 Subject: [PATCH 09/10] remove loop --- tcsocket/run.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tcsocket/run.py b/tcsocket/run.py index 3d4d46e..f07fd02 100755 --- a/tcsocket/run.py +++ b/tcsocket/run.py @@ -4,8 +4,6 @@ from functools import partial import click -from pytest_asyncio.plugin import event_loop - from app.logs import setup_logging from app.main import create_app from app.management import prepare_database, run_patch @@ -30,6 +28,7 @@ async def start_and_stop_app(app): await app.startup() await app.cleanup() + def check_app(): logger.info("initialising aiohttp app to check it's working...") app = create_app() @@ -39,12 +38,9 @@ def check_app(): logger.info('app started and stopped successfully, apparently configured correctly') - def web(): """ - Serve the application - - If the database doesn't already exist it will be created. + Serve the application, If the database doesn't already exist it will be created. """ logger.info('preparing the database...') prepare_database(False) From 96cded0ebcc8b5a695483c0e3c251d4923e4a17e Mon Sep 17 00:00:00 2001 From: Sebastian Prentice Date: Thu, 29 Jun 2023 09:36:12 +0100 Subject: [PATCH 10/10] remove loop --- tcsocket/app/main.py | 2 +- tcsocket/run.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tcsocket/app/main.py b/tcsocket/app/main.py index b3ebd64..0f8bef1 100644 --- a/tcsocket/app/main.py +++ b/tcsocket/app/main.py @@ -80,7 +80,7 @@ def setup_routes(app): app.router.add_post(r'/{company}/book-appointment', book_appointment, name='book-appointment') -def create_app(loop, *, settings: Settings = None): +def create_app(*, settings: Settings = None): app = web.Application(middlewares=middleware) settings = settings or Settings() app['settings'] = settings diff --git a/tcsocket/run.py b/tcsocket/run.py index f07fd02..3560b3f 100755 --- a/tcsocket/run.py +++ b/tcsocket/run.py @@ -40,7 +40,9 @@ def check_app(): def web(): """ - Serve the application, If the database doesn't already exist it will be created. + Serve the application + + If the database doesn't already exist it will be created. """ logger.info('preparing the database...') prepare_database(False) @@ -63,8 +65,7 @@ def load_config(self): self.cfg.set(k, v) def load(self): - loop = asyncio.get_event_loop() - return create_app(loop) + return create_app() logger.info('starting gunicorn...') Application().run()