spiff-arena/bin/wait_for_db_to_be_ready.py
burnettk 71e189afbc Squashed 'spiffworkflow-backend/' changes from 3fff3539..593f33ca
593f33ca wait for db to be ready option
706094a8 demo env and no ssl for spiff realm on that env

git-subtree-dir: spiffworkflow-backend
git-subtree-split: 593f33ca52ffb049fefd529c3a6bc011cb62e950
2022-10-16 22:32:16 -04:00

29 lines
695 B
Python

"""Grabs tickets from csv and makes process instances."""
from spiffworkflow_backend import get_hacked_up_app_for_script
from flask_bpmn.models.db import db
import sqlalchemy
import time
def try_to_connect(start_time: float) -> None:
try:
db.first_or_404('select 1')
except sqlalchemy.exc.DatabaseError as exception:
if time.time() - start_time > 15:
raise exception
else:
time.sleep(1)
try_to_connect(start_time)
def main() -> None:
"""Main."""
app = get_hacked_up_app_for_script()
start_time = time.time()
with app.app_context():
try_to_connect(start_time)
if __name__ == "__main__":
main()