diff options
author | Kristofer Hallin <kristofer@sunet.se> | 2021-11-12 10:26:19 +0100 |
---|---|---|
committer | Kristofer Hallin <kristofer@sunet.se> | 2021-11-12 10:40:56 +0100 |
commit | 5bde93857966e9007d09b96bbfdadbb6135cd113 (patch) | |
tree | e0cefccee6313c04ee802aa3169dc4125fc430bb /src | |
parent | b56fb8bc40fcf841f9cb1ebafb5283daec00e47e (diff) |
If the database is unavailable when we try to connect, make a few more attempts before giving up.
Diffstat (limited to 'src')
-rwxr-xr-x | src/wsgi.py | 16 |
1 files changed, 14 insertions, 2 deletions
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(): |