Mathias Beaulieu-Duncan
8be0ce82f6
Some checks failed
Build, Secure, and Push Docker Image on Release / build-and-push (release) Failing after 6s
34 lines
1.0 KiB
Python
Executable File
34 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import psycopg2
|
|
import sys
|
|
import time
|
|
|
|
|
|
if __name__ == '__main__':
|
|
arg_parser = argparse.ArgumentParser()
|
|
arg_parser.add_argument('--db_host', required=True)
|
|
arg_parser.add_argument('--db_port', required=True)
|
|
arg_parser.add_argument('--db_name', required=True)
|
|
arg_parser.add_argument('--db_user', required=True)
|
|
arg_parser.add_argument('--db_password', required=True)
|
|
arg_parser.add_argument('--timeout', type=int, default=5)
|
|
|
|
args = arg_parser.parse_args()
|
|
|
|
start_time = time.time()
|
|
while (time.time() - start_time) < args.timeout:
|
|
try:
|
|
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
|
|
error = ''
|
|
break
|
|
except psycopg2.OperationalError as e:
|
|
error = e
|
|
else:
|
|
conn.close()
|
|
time.sleep(1)
|
|
|
|
if error:
|
|
print("Database connection failure: %s" % error, file=sys.stderr)
|
|
sys.exit(1)
|