Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Shared state context for actions #2

Open
iduuck opened this issue Oct 13, 2023 · 0 comments
Open

Shared state context for actions #2

iduuck opened this issue Oct 13, 2023 · 0 comments

Comments

@iduuck
Copy link

iduuck commented Oct 13, 2023

It's very unhealthy for the database connection pools to always establish a new connection on each run. Also it's pretty bad to have a database connection always running (since there is maximum limit).

Hence, I would like to have a feature in the interval-py project to have a shared context for the actions, that you can access through the io object.

Imagine something like this (API borrowed from FastAPI):

@interval.on_event("startup")
async def startup_event(io: IO):
    """
    Connect to the db.
    """
    io.state['pool'] = await create_pool(...)

Which then can be used generally:

@interval.action
async def any_action(io: IO):
    async with io.state['pool'].acquire() as con:
        await con.fetch('SELECT 1')

		return f"Hello {name}"
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant