Skip to content

Commit f235b9f

Browse files
committed
rename aiopg key
1 parent e060b0f commit f235b9f

File tree

26 files changed

+83
-75
lines changed

26 files changed

+83
-75
lines changed

packages/service-library/src/servicelib/aiohttp/application_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
APP_CONFIG_KEY: Final[str] = f"{__name__ }.config"
2222
APP_SETTINGS_KEY: Final[str] = f"{__name__ }.settings"
2323

24-
APP_DB_ENGINE_KEY: Final[str] = f"{__name__ }.db_engine"
24+
APP_AIOPG_ENGINE_KEY: Final[str] = f"{__name__ }.aiopg_engine"
2525

2626
APP_CLIENT_SESSION_KEY: Final[str] = f"{__name__ }.session"
2727

packages/service-library/src/servicelib/aiohttp/db_asyncpg_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def connect_to_db(app: web.Application, settings: PostgresSettings) -> Non
5353
_set_async_engine_to_app_state(app, engine)
5454

5555
_logger.debug(
56-
"Setup engine: %s",
56+
"Setup asyncpg engine: %s",
5757
await get_pg_engine_stateinfo(engine),
5858
)
5959

packages/service-library/src/servicelib/db_asyncpg_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def create_async_engine_and_pg_database_ready(
2929
- returns engine
3030
"""
3131
with log_context(
32-
_logger, logging.DEBUG, f"connection to db {settings.dsn_with_async_sqlalchemy}"
32+
_logger, logging.DEBUG, f"Connecting to {settings.dsn_with_async_sqlalchemy}"
3333
):
3434
engine: AsyncEngine = create_async_engine(
3535
settings.dsn_with_async_sqlalchemy,
@@ -42,7 +42,9 @@ async def create_async_engine_and_pg_database_ready(
4242
future=True, # this uses sqlalchemy 2.0 API, shall be removed when sqlalchemy 2.0 is released
4343
)
4444

45-
with log_context(_logger, logging.DEBUG, "migration"):
45+
with log_context(
46+
_logger, logging.DEBUG, f"Migrating db {settings.dsn_with_async_sqlalchemy}"
47+
):
4648
try:
4749
await raise_if_migration_not_ready(engine)
4850
except Exception:

services/storage/src/simcore_service_storage/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
MAX_CONCURRENT_REST_CALLS: Final[int] = 10
4040

4141
# DATABASE ----------------------------
42-
APP_DB_ENGINE_KEY = f"{__name__}.db_engine"
42+
APP_AIOPG_ENGINE_KEY = f"{__name__}.db_engine"
4343
MAX_CONCURRENT_DB_TASKS: Final[int] = 2
4444

4545
# DATA STORAGE MANAGER ----------------------------------

services/storage/src/simcore_service_storage/db.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from tenacity import retry
1515

16-
from .constants import APP_CONFIG_KEY, APP_DB_ENGINE_KEY
16+
from .constants import APP_AIOPG_ENGINE_KEY, APP_CONFIG_KEY
1717

1818
_logger = logging.getLogger(__name__)
1919

@@ -46,7 +46,7 @@ async def postgres_cleanup_ctx(app: web.Application):
4646
) as engine:
4747

4848
assert engine # nosec
49-
app[APP_DB_ENGINE_KEY] = engine
49+
app[APP_AIOPG_ENGINE_KEY] = engine
5050
_logger.info("Created pg engine for %s", dsn)
5151
yield # ----------
5252
_logger.info("Deleting pg engine for %s", dsn)
@@ -55,19 +55,19 @@ async def postgres_cleanup_ctx(app: web.Application):
5555

5656
async def is_service_responsive(app: web.Application) -> bool:
5757
"""Returns true if the app can connect to db service"""
58-
return await is_pg_responsive(engine=app[APP_DB_ENGINE_KEY])
58+
return await is_pg_responsive(engine=app[APP_AIOPG_ENGINE_KEY])
5959

6060

6161
def get_engine_state(app: web.Application) -> dict[str, Any]:
62-
engine: Engine | None = app.get(APP_DB_ENGINE_KEY)
62+
engine: Engine | None = app.get(APP_AIOPG_ENGINE_KEY)
6363
if engine:
6464
engine_info: dict[str, Any] = get_pg_engine_stateinfo(engine)
6565
return engine_info
6666
return {}
6767

6868

6969
def setup_db(app: web.Application):
70-
app[APP_DB_ENGINE_KEY] = None
70+
app[APP_AIOPG_ENGINE_KEY] = None
7171

7272
# app is created at this point but not yet started
7373
_logger.debug("Setting up %s [service: %s] ...", __name__, "postgres")

services/storage/src/simcore_service_storage/db_tokens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from models_library.users import UserID
88
from simcore_postgres_database.storage_models import tokens
99

10-
from .constants import APP_CONFIG_KEY, APP_DB_ENGINE_KEY
10+
from .constants import APP_AIOPG_ENGINE_KEY, APP_CONFIG_KEY
1111

1212
log = logging.getLogger(__name__)
1313

@@ -27,7 +27,7 @@ async def get_api_token_and_secret(
2727
app: web.Application, user_id: UserID
2828
) -> tuple[str, str]:
2929
# from the client side together with the userid?
30-
engine = app[APP_DB_ENGINE_KEY]
30+
engine = app[APP_AIOPG_ENGINE_KEY]
3131

3232
# defaults from config if any, othewise None
3333
api_token = app[APP_CONFIG_KEY].BF_API_KEY

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838

3939
from . import db_file_meta_data, db_projects, db_tokens
4040
from .constants import (
41+
APP_AIOPG_ENGINE_KEY,
4142
APP_CONFIG_KEY,
42-
APP_DB_ENGINE_KEY,
4343
DATCORE_ID,
4444
EXPAND_DIR_MAX_ITEM_COUNT,
4545
MAX_CONCURRENT_S3_TASKS,
@@ -1084,7 +1084,7 @@ def create_simcore_s3_data_manager(app: web.Application) -> SimcoreS3DataManager
10841084
cfg: Settings = app[APP_CONFIG_KEY]
10851085
assert cfg.STORAGE_S3 # nosec
10861086
return SimcoreS3DataManager(
1087-
engine=app[APP_DB_ENGINE_KEY],
1087+
engine=app[APP_AIOPG_ENGINE_KEY],
10881088
simcore_bucket_name=parse_obj_as(S3BucketName, cfg.STORAGE_S3.S3_BUCKET_NAME),
10891089
app=app,
10901090
settings=cfg,

services/web/server/src/simcore_service_webserver/_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from typing import Final
55

66
from servicelib.aiohttp.application_keys import (
7+
APP_AIOPG_ENGINE_KEY,
78
APP_CONFIG_KEY,
8-
APP_DB_ENGINE_KEY,
99
APP_FIRE_AND_FORGET_TASKS_KEY,
1010
APP_SETTINGS_KEY,
1111
)
@@ -30,7 +30,7 @@
3030

3131
__all__: tuple[str, ...] = (
3232
"APP_CONFIG_KEY",
33-
"APP_DB_ENGINE_KEY",
33+
"APP_AIOPG_ENGINE_KEY",
3434
"APP_FIRE_AND_FORGET_TASKS_KEY",
3535
"APP_SETTINGS_KEY",
3636
"RQT_USERID_KEY",

services/web/server/src/simcore_service_webserver/api_keys/_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from models_library.basic_types import IdInt
1111
from models_library.products import ProductName
1212
from models_library.users import UserID
13-
from servicelib.aiohttp.application_keys import APP_DB_ENGINE_KEY
13+
from servicelib.aiohttp.application_keys import APP_AIOPG_ENGINE_KEY
1414
from simcore_postgres_database.models.api_keys import api_keys
1515
from sqlalchemy.dialects.postgresql import insert as pg_insert
1616

@@ -23,7 +23,7 @@ class ApiKeyRepo:
2323

2424
@classmethod
2525
def create_from_app(cls, app: web.Application):
26-
return cls(engine=app[APP_DB_ENGINE_KEY])
26+
return cls(engine=app[APP_AIOPG_ENGINE_KEY])
2727

2828
async def list_names(
2929
self, *, user_id: UserID, product_name: ProductName

services/web/server/src/simcore_service_webserver/db/_aiopg.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from aiopg.sa import Engine, create_engine
1313
from models_library.utils.json_serialization import json_dumps
1414
from servicelib.aiohttp.aiopg_utils import is_pg_responsive
15-
from servicelib.aiohttp.application_keys import APP_DB_ENGINE_KEY
15+
from servicelib.aiohttp.application_keys import APP_AIOPG_ENGINE_KEY
1616
from servicelib.retry_policies import PostgresRetryPolicyUponInitialization
1717
from simcore_postgres_database.errors import DBAPIError
1818
from simcore_postgres_database.utils_aiopg import (
@@ -53,43 +53,48 @@ async def postgres_cleanup_ctx(app: web.Application) -> AsyncIterator[None]:
5353

5454
settings = get_plugin_settings(app)
5555
aiopg_engine = await _ensure_pg_ready(settings)
56-
app[APP_DB_ENGINE_KEY] = aiopg_engine
56+
app[APP_AIOPG_ENGINE_KEY] = aiopg_engine
5757

58-
_logger.info("pg engine created %s", json_dumps(get_engine_state(app), indent=1))
58+
_logger.info(
59+
"app[APP_AIOPG_ENGINE_KEY] created %s",
60+
json_dumps(get_engine_state(app), indent=1),
61+
)
5962

6063
yield # -------------------
6164

62-
if aiopg_engine is not app.get(APP_DB_ENGINE_KEY):
63-
_logger.critical("app does not hold right db engine. Somebody has changed it??")
65+
if aiopg_engine is not app.get(APP_AIOPG_ENGINE_KEY):
66+
_logger.critical(
67+
"app[APP_AIOPG_ENGINE_KEY] does not hold right db engine. Somebody has changed it??"
68+
)
6469

6570
await close_engine(aiopg_engine)
6671

6772
_logger.debug(
68-
"pg engine created after shutdown %s (closed=%s): %s",
73+
"app[APP_AIOPG_ENGINE_KEY] after shutdown %s (closed=%s): %s",
6974
aiopg_engine.dsn,
7075
aiopg_engine.closed,
7176
json_dumps(get_engine_state(app), indent=1),
7277
)
7378

7479

7580
def is_service_enabled(app: web.Application):
76-
return app.get(APP_DB_ENGINE_KEY) is not None
81+
return app.get(APP_AIOPG_ENGINE_KEY) is not None
7782

7883

7984
async def is_service_responsive(app: web.Application):
8085
"""Returns true if the app can connect to db service"""
8186
if not is_service_enabled(app):
8287
return False
83-
return await is_pg_responsive(engine=app[APP_DB_ENGINE_KEY])
88+
return await is_pg_responsive(engine=app[APP_AIOPG_ENGINE_KEY])
8489

8590

8691
def get_engine_state(app: web.Application) -> dict[str, Any]:
87-
engine: Engine | None = app.get(APP_DB_ENGINE_KEY)
92+
engine: Engine | None = app.get(APP_AIOPG_ENGINE_KEY)
8893
if engine:
8994
pg_engine_stateinfo: dict[str, Any] = get_pg_engine_stateinfo(engine)
9095
return pg_engine_stateinfo
9196
return {}
9297

9398

9499
def get_database_engine(app: web.Application) -> Engine:
95-
return cast(Engine, app[APP_DB_ENGINE_KEY])
100+
return cast(Engine, app[APP_AIOPG_ENGINE_KEY])

0 commit comments

Comments
 (0)