ping postgres with pg_isready
This commit is contained in:
parent
fd27217ba8
commit
225c26d4d9
|
@ -10,7 +10,7 @@ def test():
|
|||
|
||||
|
||||
def ping_mysql(host, port, username, password) -> int:
|
||||
"""Check if the database is up and can be reached"""
|
||||
"""Check if the mysql is up and can be reached"""
|
||||
return run([
|
||||
'mysqladmin',
|
||||
'ping',
|
||||
|
@ -25,7 +25,7 @@ def ping_mysql(host, port, username, password) -> int:
|
|||
|
||||
|
||||
def ping_mariadb(host, port, username, password) -> int:
|
||||
"""Check if the database is up and can be reached"""
|
||||
"""Check if the mariadb is up and can be reached"""
|
||||
return run([
|
||||
'mysqladmin',
|
||||
'ping',
|
||||
|
@ -39,8 +39,14 @@ def ping_mariadb(host, port, username, password) -> int:
|
|||
])
|
||||
|
||||
|
||||
def ping_postgres(self) -> int:
|
||||
return -1
|
||||
def ping_postgres(host, port, username, password) -> int:
|
||||
"""Check if postgres can be reached"""
|
||||
return run([
|
||||
"pg_isready",
|
||||
f"--host={host}",
|
||||
f"--port={port}",
|
||||
f"--username={username}",
|
||||
])
|
||||
|
||||
|
||||
def run(cmd: List[str]) -> int:
|
||||
|
|
|
@ -70,8 +70,13 @@ class PostgresContainer(Container):
|
|||
|
||||
def ping(self) -> bool:
|
||||
"""Check the availability of the service"""
|
||||
# raise NotImplementedError("Base container class don't implement this")
|
||||
print("Implement postgres ping!")
|
||||
creds = self.get_credentials()
|
||||
return commands.ping_postgres(
|
||||
creds['host'],
|
||||
creds['port'],
|
||||
creds['username'],
|
||||
creds['password'],
|
||||
)
|
||||
|
||||
def dump_command(self) -> list:
|
||||
"""list: create a dump command restic and use to send data through stdin"""
|
||||
|
|
Loading…
Reference in New Issue