Improvements for psql wait script.

* support: Move to shared directory to avoid code drift.
* feat: Make DB name configurable
This commit is contained in:
Josh Santos 2024-03-31 17:52:18 -04:00
parent 0daa6ed770
commit 5740583e38
No known key found for this signature in database
GPG Key ID: F40E8260EF912E41
3 changed files with 21 additions and 12 deletions

View File

@ -10,21 +10,24 @@ if __name__ == '__main__':
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args()
conn = None
start_time = time.time()
error = ''
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='postgres')
error = ''
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
conn.close()
break
except psycopg2.OperationalError as e:
error = e
else:
conn.close()
time.sleep(1)
if error:

View File

@ -10,21 +10,24 @@ if __name__ == '__main__':
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args()
conn = None
start_time = time.time()
error = ''
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='postgres')
error = ''
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
conn.close()
break
except psycopg2.OperationalError as e:
error = e
else:
conn.close()
time.sleep(1)
if error:

View File

@ -10,21 +10,24 @@ if __name__ == '__main__':
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args()
conn = None
start_time = time.time()
error = ''
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='postgres')
error = ''
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
conn.close()
break
except psycopg2.OperationalError as e:
error = e
else:
conn.close()
time.sleep(1)
if error: