From 5bde93857966e9007d09b96bbfdadbb6135cd113 Mon Sep 17 00:00:00 2001 From: Kristofer Hallin Date: Fri, 12 Nov 2021 10:26:19 +0100 Subject: If the database is unavailable when we try to connect, make a few more attempts before giving up. --- src/wsgi.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/wsgi.py') diff --git a/src/wsgi.py b/src/wsgi.py index b6a1a10..e090876 100755 --- a/src/wsgi.py +++ b/src/wsgi.py @@ -8,11 +8,23 @@ from fastapi_jwt_auth import AuthJWT from fastapi_jwt_auth.exceptions import AuthJWTException from pydantic import BaseModel from index import CouchIindex - +import time from db import DictDB app = FastAPI() -db = DictDB() + +for i in range(10): + try: + db = DictDB() + except Exception: + print( + f'Database not responding, will try again soon. Attempt {i + 1} of 10.') + else: + break + time.sleep(10) +else: + print('Database did not respond after 10 attempts, quitting.') + sys.exit(-1) def get_pubkey(): -- cgit v1.1