Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection quality feature #304

Open
kalombos opened this issue Oct 25, 2024 · 0 comments
Open

Connection quality feature #304

kalombos opened this issue Oct 25, 2024 · 0 comments

Comments

@kalombos
Copy link
Collaborator

kalombos commented Oct 25, 2024

We need add to callback to PoolBackend to check connection like in pyscopg3

Some useful snippets:

psycopg3 check connection method:

@staticmethod
    def check_connection(conn: CT) -> None:
        """
        A simple check to verify that a connection is still working.

        Return quietly if the connection is still working, otherwise raise
        an exception.

        Used internally by `check()`, but also available for client usage,
        for instance as `!check` callback when a pool is created.
        """
        if conn.autocommit:
            conn.execute("")
        else:
            conn.autocommit = True
            try:
                conn.execute("")
            finally:
                conn.autocommit = False

Some implementation of healthcheck for peewee-async

class CheckPoolBackend(PoolBackend):
    async def acquire(self):
        while True:
            conn = await super().acquire()
            try:
                await conn.execute("Select 1") # our healtcheck query
            except Exception:
                conn.close()
                self.release(conn)
            else:
                return conn
            # https://github.com/psycopg/psycopg/blob/master/psycopg_pool/psycopg_pool/pool.py#L220
            # AttemptWithBackoff
@kalombos kalombos changed the title Connection quality opportunity Connection quality feature Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant