Skip to content

Connection quality feature #304

@kalombos

Description

@kalombos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions