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:
|
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([
|
return run([
|
||||||
'mysqladmin',
|
'mysqladmin',
|
||||||
'ping',
|
'ping',
|
||||||
|
@ -25,7 +25,7 @@ def ping_mysql(host, port, username, password) -> int:
|
||||||
|
|
||||||
|
|
||||||
def ping_mariadb(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([
|
return run([
|
||||||
'mysqladmin',
|
'mysqladmin',
|
||||||
'ping',
|
'ping',
|
||||||
|
@ -39,8 +39,14 @@ def ping_mariadb(host, port, username, password) -> int:
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def ping_postgres(self) -> int:
|
def ping_postgres(host, port, username, password) -> int:
|
||||||
return -1
|
"""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:
|
def run(cmd: List[str]) -> int:
|
||||||
|
|
|
@ -70,8 +70,13 @@ class PostgresContainer(Container):
|
||||||
|
|
||||||
def ping(self) -> bool:
|
def ping(self) -> bool:
|
||||||
"""Check the availability of the service"""
|
"""Check the availability of the service"""
|
||||||
# raise NotImplementedError("Base container class don't implement this")
|
creds = self.get_credentials()
|
||||||
print("Implement postgres ping!")
|
return commands.ping_postgres(
|
||||||
|
creds['host'],
|
||||||
|
creds['port'],
|
||||||
|
creds['username'],
|
||||||
|
creds['password'],
|
||||||
|
)
|
||||||
|
|
||||||
def dump_command(self) -> list:
|
def dump_command(self) -> list:
|
||||||
"""list: create a dump command restic and use to send data through stdin"""
|
"""list: create a dump command restic and use to send data through stdin"""
|
||||||
|
|
Loading…
Reference in New Issue