diff --git a/alws/dramatiq/__init__.py b/alws/dramatiq/__init__.py index d7a4ede2..60a26b80 100644 --- a/alws/dramatiq/__init__.py +++ b/alws/dramatiq/__init__.py @@ -8,12 +8,10 @@ and it's important for all tasks which involves user interaction to have priority 0. 4. If you need to use async function in your dramatiq task - ALWAYS use - loop from this __init__.py, since creating multiple loops for tasks + loop from this _event_loop.py, since creating multiple loops for tasks will break your tasks. """ -import asyncio - import dramatiq from dramatiq.brokers.rabbitmq import RabbitmqBroker @@ -27,7 +25,6 @@ f"{settings.rabbitmq_default_vhost}", ) dramatiq.set_broker(rabbitmq_broker) -event_loop = asyncio.get_event_loop() # Tasks import started from here from alws.dramatiq.build import build_done, start_build diff --git a/alws/dramatiq/_event_loop.py b/alws/dramatiq/_event_loop.py new file mode 100644 index 00000000..62c54dfe --- /dev/null +++ b/alws/dramatiq/_event_loop.py @@ -0,0 +1,3 @@ +import asyncio + +event_loop = asyncio.get_event_loop() diff --git a/alws/dramatiq/build.py b/alws/dramatiq/build.py index e5df5cb9..04361f52 100644 --- a/alws/dramatiq/build.py +++ b/alws/dramatiq/build.py @@ -21,7 +21,7 @@ from alws.crud import build_node as build_node_crud from alws.crud import test from alws.dependencies import get_async_db_key -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.errors import ( ArtifactConversionError, ModuleUpdateError, diff --git a/alws/dramatiq/errata.py b/alws/dramatiq/errata.py index d4ecfcd9..ffb04cfa 100644 --- a/alws/dramatiq/errata.py +++ b/alws/dramatiq/errata.py @@ -10,7 +10,7 @@ release_new_errata_record, reset_matched_erratas_packages_threshold, ) -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.utils.fastapi_sqla_setup import setup_all __all__ = ["release_errata"] diff --git a/alws/dramatiq/products.py b/alws/dramatiq/products.py index db88dfd3..9dadbf91 100644 --- a/alws/dramatiq/products.py +++ b/alws/dramatiq/products.py @@ -13,7 +13,7 @@ from alws.config import settings from alws.constants import DRAMATIQ_TASK_TIMEOUT, BuildTaskStatus from alws.dependencies import get_async_db_key -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.utils.fastapi_sqla_setup import setup_all from alws.utils.log_utils import setup_logger from alws.utils.pulp_client import PulpClient diff --git a/alws/dramatiq/releases.py b/alws/dramatiq/releases.py index b9e035cd..5a3a8f9c 100644 --- a/alws/dramatiq/releases.py +++ b/alws/dramatiq/releases.py @@ -1,12 +1,10 @@ -from contextlib import asynccontextmanager - import dramatiq from fastapi_sqla import open_async_session from alws.constants import DRAMATIQ_TASK_TIMEOUT from alws.crud import release as r_crud from alws.dependencies import get_async_db_key -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.utils.fastapi_sqla_setup import setup_all __all__ = ["execute_release_plan"] diff --git a/alws/dramatiq/sign_task.py b/alws/dramatiq/sign_task.py index dd769999..6d4b731c 100644 --- a/alws/dramatiq/sign_task.py +++ b/alws/dramatiq/sign_task.py @@ -4,7 +4,7 @@ from alws.constants import DRAMATIQ_TASK_TIMEOUT from alws.crud import sign_task -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.schemas import sign_schema from alws.utils.fastapi_sqla_setup import setup_all diff --git a/alws/dramatiq/tests.py b/alws/dramatiq/tests.py index f3aef1a8..d68e9ff7 100644 --- a/alws/dramatiq/tests.py +++ b/alws/dramatiq/tests.py @@ -7,7 +7,7 @@ from alws.constants import DRAMATIQ_TASK_TIMEOUT, TestTaskStatus from alws.crud import test as t_crud from alws.dependencies import get_async_db_key -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.schemas.test_schema import TestTaskResult from alws.utils.fastapi_sqla_setup import setup_all diff --git a/alws/dramatiq/user.py b/alws/dramatiq/user.py index 0c7d918f..127f47af 100644 --- a/alws/dramatiq/user.py +++ b/alws/dramatiq/user.py @@ -7,7 +7,7 @@ from alws.constants import DRAMATIQ_TASK_TIMEOUT from alws.crud import build as build_crud from alws.dependencies import get_async_db_key -from alws.dramatiq import event_loop +from alws.dramatiq._event_loop import event_loop from alws.utils.fastapi_sqla_setup import setup_all __all__ = ['perform_user_removal'] diff --git a/alws/routers/releases.py b/alws/routers/releases.py index de00e6fe..acd20ce2 100644 --- a/alws/routers/releases.py +++ b/alws/routers/releases.py @@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends from fastapi_sqla import AsyncSessionDependency -from sqlalchemy import update +from sqlalchemy import select, update from sqlalchemy.ext.asyncio import AsyncSession from alws import models