Skip to content

DB session from a worker function? #138

@kaStoyanov

Description

@kaStoyanov

Hey, Im trying for 2 days now to make this work,
How do I pass the session from an endpoint to the background worker function?

My idea is to insert a record in the db from my endpoint then process it from the background function.

Edit

I made it work by creating another function with contextmanager

@asynccontextmanager
async def async_get_context() -> AsyncSession:
    async_session = local_session
    async with async_session() as db:
        yield db

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions