Skip to content

Commit

Permalink
Improvements for psql wait script.
Browse files Browse the repository at this point in the history
* support: Move to shared directory to avoid code drift.
* feat: Make DB name configurable
  • Loading branch information
thatnerdjosh committed Mar 31, 2024
1 parent 0daa6ed commit c446a5b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
11 changes: 7 additions & 4 deletions 15.0/wait-for-psql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
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:
Expand Down
2 changes: 1 addition & 1 deletion 16.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ EXPOSE 8069 8071 8072
# Set the default config file
ENV ODOO_RC /etc/odoo/odoo.conf

COPY wait-for-psql.py /usr/local/bin/wait-for-psql.py
COPY ../shared/wait-for-psql.py /usr/local/bin/wait-for-psql.py

# Set default user when running the container
USER odoo
Expand Down
11 changes: 7 additions & 4 deletions 16.0/wait-for-psql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
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:
Expand Down
11 changes: 7 additions & 4 deletions 17.0/wait-for-psql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
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:
Expand Down

0 comments on commit c446a5b

Please sign in to comment.