Skip to content

Commit 2ba1550

Browse files
Fix gunicorn deployments that fail to start indexing due to multiple application instances being created. (#473)
1 parent 1e47a9a commit 2ba1550

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

knowledge_repo/app/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, repo, db_uri=None, debug=None, config=None, **kwargs):
4747
# Add unique identifier for this application isinstance
4848
self.uuid = str(uuid.uuid4())
4949
if 'KNOWLEDGE_REPO_MASTER_UUID' not in os.environ:
50+
logger.info("Set KNOWLEDGE_REPO_MASTER_UUID to '{}'.".format(self.uuid))
5051
os.environ['KNOWLEDGE_REPO_MASTER_UUID'] = self.uuid
5152

5253
# Preload default configuration

knowledge_repo/app/deploy/common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def builder_func(self):
7575

7676
@property
7777
def app(self):
78-
return self.builder_func()
78+
try:
79+
self.__app
80+
except AttributeError:
81+
self.__app = self.builder_func()
82+
return self.__app
7983

8084
def write_temp_files(self):
8185
import tempfile

knowledge_repo/app/deploy/gunicorn.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ def load_config(self):
4141
self.cfg.set(key, value)
4242

4343
def load(self):
44-
return self.builder_func()
45-
46-
def run(self):
4744
if not self.app.check_thread_support():
4845
raise RuntimeError("Database configuration is not suitable for deployment (not thread-safe).")
49-
self.app.start_indexing()
50-
return BaseApplication.run(self)
46+
return self.app.start_indexing()

knowledge_repo/app/index.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def set_up_indexing_timers(app):
2828
logger.info("Not spawning index-sync timers for non-master application instance: {}".format(app.uuid))
2929
return
3030

31+
logger.info("Spawning index-sync timers for master application instance: {}".format(app.uuid))
32+
3133
def index_watchdog(app):
3234
while True:
3335
if not hasattr(app, 'sync_thread') or not app.sync_thread.is_alive():

0 commit comments

Comments
 (0)