I've created this repository to investigate how DB connections behave under the stack of SQLAlchemy 2, asyncio and Pubsub.
Given you have Python properly installed with poetry:
-
Create .env from env.sample
-
Start Pubsub
make pubsub_build
make pubsub_up
make pubsub_create_topic
make pubsub_create_subscription
make pubsub_up
- Start poetry
poetry install
poetry shell
- Start database
make db_up
make db_upgrade
task.py
file connects to database, you have 4 options:
async_session as async_session,
async_session_null as async_session_null,
session_factory,
session_null_factory,
So you can use:
async for db_session in session_factory():
# OR
async for db_session in session_null_factory():
# OR
async with async_session() as db_session:
# OR
async with async_session_null() as db_session:
In order to configure grafana you must add Jaeger data source (URL: http://jaeger:16686)
make pubsub_producer
make run_task