Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay starting indexing until actually deploying server. #465

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions knowledge_repo/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ def ensure_excluded_tags_exist():
Tag(name=tag)
db_session.commit()

# Set up indexing timers
set_up_indexing_timers(self)

@self.before_request
def open_repository_session():
if not request.path.startswith('/static'):
Expand Down Expand Up @@ -318,6 +315,9 @@ def db_update_index(self, check_timeouts=True, force=False, reindex=False):
with self.app_context():
update_index(check_timeouts=check_timeouts, force=force, reindex=reindex)

def start_indexing(self):
set_up_indexing_timers(self)

def check_thread_support(self, check_index=True, check_repositories=True):
# If index database is an sqlite database, it will lock on any write action, and so breaks on multiple threads
# Repository uris will break as above (but less often since they are not often written too), but will also
Expand Down
18 changes: 12 additions & 6 deletions knowledge_repo/app/deploy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

def get_app_builder(uris, debug, db_uri, config, **kwargs):
def get_app():
return knowledge_repo.KnowledgeRepository.for_uri(uris).get_app(db_uri=db_uri, debug=debug, config=config, **kwargs)
return (
knowledge_repo.KnowledgeRepository
.for_uri(uris)
.get_app(db_uri=db_uri, debug=debug, config=config, **kwargs)
)
return get_app


Expand All @@ -24,7 +28,8 @@ def __init__(self,
port=7000,
workers=4,
timeout=60):
assert isinstance(knowledge_builder, (str, types.FunctionType)), u"Unknown builder type {}".format(type(knowledge_builder))
assert isinstance(knowledge_builder, (str, types.FunctionType)), \
u"Unknown builder type {}".format(type(knowledge_builder))
self.knowledge_builder = knowledge_builder
self.host = host
self.port = port
Expand All @@ -36,13 +41,13 @@ def using(cls, engine):
if engine == 'gunicorn':
if sys.platform == 'win32':
raise RuntimeError(
"`gunicorn` deployer is not available for Windows. Please use "
"`uwsgi` or `flask` engines instead."
"`gunicorn` deployer is not available for Windows. Please "
"use `uwsgi` or `flask` engines instead."
)
elif 'gunicorn' not in cls._registry:
raise RuntimeError(
"`gunicorn` does not appear to be installed. Please install "
"it and try again."
"`gunicorn` does not appear to be installed. Please "
"install it and try again."
)
return cls._get_subclass_for(engine)

Expand Down Expand Up @@ -87,6 +92,7 @@ def write_temp_files(self):
out.append(self.builder_str)
if not isinstance(self.knowledge_builder, str):
out.append('app = %s()' % self.knowledge_builder.__name__)
out.append('app.start_indexing()')

with open(tmp_path, 'w') as f:
f.write(u'\n'.join(out))
Expand Down
8 changes: 4 additions & 4 deletions knowledge_repo/app/deploy/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class FlaskDeployer(KnowledgeDeployer):
_registry_keys = ['flask']

def run(self, **kwargs):
app = self.app
return app.run(
debug=app.config['DEBUG'],
self.app.start_indexing()
return self.app.run(
debug=self.app.config['DEBUG'],
host=self.host,
port=self.port,
threaded=app.check_thread_support(),
threaded=self.app.check_thread_support(),
**kwargs
)
1 change: 1 addition & 0 deletions knowledge_repo/app/deploy/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ def load(self):
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)