spiffworkflow-backend/bin/wait_for_db_to_be_ready.py

32 lines
723 B
Python
Raw Normal View History

2022-10-17 02:31:55 +00:00
"""Grabs tickets from csv and makes process instances."""
import time
2022-10-17 02:31:55 +00:00
import sqlalchemy
from flask_bpmn.models.db import db
from spiffworkflow_backend import get_hacked_up_app_for_script
2022-10-17 02:31:55 +00:00
def try_to_connect(start_time: float) -> None:
"""Try to connect."""
2022-10-17 02:31:55 +00:00
try:
db.first_or_404("select 1")
2022-10-17 02:31:55 +00:00
except sqlalchemy.exc.DatabaseError as exception:
if time.time() - start_time > 15:
raise exception
else:
time.sleep(1)
try_to_connect(start_time)
2022-10-17 02:31:55 +00:00
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()