| |
@@ -1,7 +1,10 @@
|
| |
# SPDX-License-Identifier: GPL-2.0+
|
| |
|
| |
+ import time
|
| |
import click
|
| |
from flask.cli import FlaskGroup
|
| |
+ from sqlalchemy.exc import OperationalError
|
| |
+ from waiverdb.models import db
|
| |
|
| |
|
| |
def create_waiver_app(_):
|
| |
@@ -14,5 +17,23 @@
|
| |
pass
|
| |
|
| |
|
| |
+ @cli.command(name='wait-for-db')
|
| |
+ def wait_for_db():
|
| |
+ """
|
| |
+ Wait until database server is reachable.
|
| |
+ """
|
| |
+ poll_interval = 10 # seconds
|
| |
+ while True:
|
| |
+ try:
|
| |
+ db.engine.connect()
|
| |
+ except OperationalError as e:
|
| |
+ click.echo('Failed to connect to database: {}'.format(e))
|
| |
+ click.echo('Sleeping for {} seconds...'.format(poll_interval))
|
| |
+ time.sleep(poll_interval)
|
| |
+ click.echo('Retrying...')
|
| |
+ else:
|
| |
+ break
|
| |
+
|
| |
+
|
| |
if __name__ == '__main__':
|
| |
cli() # pylint: disable=E1120
|
| |
... not a post-start pod hook for the web app. This way, we can see the
logs of the migration pod, and if the migration fails the deployment
will be aborted.
The database migration pod has to first wait for the Postgres pod to
finish starting up, because in a freshly created environment (as in the
tests) the migration pod is started concurrently with the Postgres pod.
Fixes #121.