diff --git a/legal-api/gunicorn_config.py b/legal-api/gunicorn_config.py index c4eb50acf..dbcc1e0b5 100755 --- a/legal-api/gunicorn_config.py +++ b/legal-api/gunicorn_config.py @@ -16,9 +16,13 @@ """ import os +import gunicorn_server workers = int(os.environ.get('GUNICORN_PROCESSES', '1')) # pylint: disable=invalid-name threads = int(os.environ.get('GUNICORN_THREADS', '1')) # pylint: disable=invalid-name forwarded_allow_ips = '*' # pylint: disable=invalid-name secure_scheme_headers = {'X-Forwarded-Proto': 'https'} # pylint: disable=invalid-name + +# Server Hooks +pre_fork = gunicorn_server.pre_fork diff --git a/legal-api/gunicorn_server.py b/legal-api/gunicorn_server.py new file mode 100644 index 000000000..62168b81a --- /dev/null +++ b/legal-api/gunicorn_server.py @@ -0,0 +1,12 @@ + +import time + + +def pre_fork(server, worker): + # Delay loading of each worker by 5 seconds + # This is done to work around an issue where the Traction API is returning an invalid token. The issue happens + # when successive token retrieval calls are made with less than 2-3 seconds between the calls. + time.sleep(5) + + +pre_fork = pre_fork