-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Description
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 = FalseSome 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
# AttemptWithBackoffReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels