Skip to content

Commit

Permalink
Fix gunicorn deployments that fail to start indexing due to multiple …
Browse files Browse the repository at this point in the history
…application instances being created. (#473)
  • Loading branch information
matthewwardrop authored Dec 12, 2018
1 parent 1e47a9a commit 2ba1550
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions knowledge_repo/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, repo, db_uri=None, debug=None, config=None, **kwargs):
# Add unique identifier for this application isinstance
self.uuid = str(uuid.uuid4())
if 'KNOWLEDGE_REPO_MASTER_UUID' not in os.environ:
logger.info("Set KNOWLEDGE_REPO_MASTER_UUID to '{}'.".format(self.uuid))
os.environ['KNOWLEDGE_REPO_MASTER_UUID'] = self.uuid

# Preload default configuration
Expand Down
6 changes: 5 additions & 1 deletion knowledge_repo/app/deploy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ def builder_func(self):

@property
def app(self):
return self.builder_func()
try:
self.__app
except AttributeError:
self.__app = self.builder_func()
return self.__app

def write_temp_files(self):
import tempfile
Expand Down
6 changes: 1 addition & 5 deletions knowledge_repo/app/deploy/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ def load_config(self):
self.cfg.set(key, value)

def load(self):
return self.builder_func()

def run(self):
if not self.app.check_thread_support():
raise RuntimeError("Database configuration is not suitable for deployment (not thread-safe).")
self.app.start_indexing()
return BaseApplication.run(self)
return self.app.start_indexing()
2 changes: 2 additions & 0 deletions knowledge_repo/app/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def set_up_indexing_timers(app):
logger.info("Not spawning index-sync timers for non-master application instance: {}".format(app.uuid))
return

logger.info("Spawning index-sync timers for master application instance: {}".format(app.uuid))

def index_watchdog(app):
while True:
if not hasattr(app, 'sync_thread') or not app.sync_thread.is_alive():
Expand Down

0 comments on commit 2ba1550

Please sign in to comment.