Skip to content

Commit 60e46ad

Browse files
Delay starting indexing until actually deploying server. (#465)
1 parent a47ada5 commit 60e46ad

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

knowledge_repo/app/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ def ensure_excluded_tags_exist():
195195
Tag(name=tag)
196196
db_session.commit()
197197

198-
# Set up indexing timers
199-
set_up_indexing_timers(self)
200-
201198
@self.before_request
202199
def open_repository_session():
203200
if not request.path.startswith('/static'):
@@ -322,6 +319,9 @@ def db_update_index(self, check_timeouts=True, force=False, reindex=False):
322319
with self.app_context():
323320
update_index(check_timeouts=check_timeouts, force=force, reindex=reindex)
324321

322+
def start_indexing(self):
323+
set_up_indexing_timers(self)
324+
325325
def check_thread_support(self, check_index=True, check_repositories=True):
326326
# If index database is an sqlite database, it will lock on any write action, and so breaks on multiple threads
327327
# Repository uris will break as above (but less often since they are not often written too), but will also

knowledge_repo/app/deploy/common.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
def get_app_builder(uris, debug, db_uri, config, **kwargs):
1414
def get_app():
15-
return knowledge_repo.KnowledgeRepository.for_uri(uris).get_app(db_uri=db_uri, debug=debug, config=config, **kwargs)
15+
return (
16+
knowledge_repo.KnowledgeRepository
17+
.for_uri(uris)
18+
.get_app(db_uri=db_uri, debug=debug, config=config, **kwargs)
19+
)
1620
return get_app
1721

1822

@@ -24,7 +28,8 @@ def __init__(self,
2428
port=7000,
2529
workers=4,
2630
timeout=60):
27-
assert isinstance(knowledge_builder, (str, types.FunctionType)), u"Unknown builder type {}".format(type(knowledge_builder))
31+
assert isinstance(knowledge_builder, (str, types.FunctionType)), \
32+
u"Unknown builder type {}".format(type(knowledge_builder))
2833
self.knowledge_builder = knowledge_builder
2934
self.host = host
3035
self.port = port
@@ -36,13 +41,13 @@ def using(cls, engine):
3641
if engine == 'gunicorn':
3742
if sys.platform == 'win32':
3843
raise RuntimeError(
39-
"`gunicorn` deployer is not available for Windows. Please use "
40-
"`uwsgi` or `flask` engines instead."
44+
"`gunicorn` deployer is not available for Windows. Please "
45+
"use `uwsgi` or `flask` engines instead."
4146
)
4247
elif 'gunicorn' not in cls._registry:
4348
raise RuntimeError(
44-
"`gunicorn` does not appear to be installed. Please install "
45-
"it and try again."
49+
"`gunicorn` does not appear to be installed. Please "
50+
"install it and try again."
4651
)
4752
return cls._get_subclass_for(engine)
4853

@@ -87,6 +92,7 @@ def write_temp_files(self):
8792
out.append(self.builder_str)
8893
if not isinstance(self.knowledge_builder, str):
8994
out.append('app = %s()' % self.knowledge_builder.__name__)
95+
out.append('app.start_indexing()')
9096

9197
with open(tmp_path, 'w') as f:
9298
f.write(u'\n'.join(out))

knowledge_repo/app/deploy/flask.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class FlaskDeployer(KnowledgeDeployer):
66
_registry_keys = ['flask']
77

88
def run(self, **kwargs):
9-
app = self.app
10-
return app.run(
11-
debug=app.config['DEBUG'],
9+
self.app.start_indexing()
10+
return self.app.run(
11+
debug=self.app.config['DEBUG'],
1212
host=self.host,
1313
port=self.port,
14-
threaded=app.check_thread_support(),
14+
threaded=self.app.check_thread_support(),
1515
**kwargs
1616
)

knowledge_repo/app/deploy/gunicorn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ def load(self):
4646
def run(self):
4747
if not self.app.check_thread_support():
4848
raise RuntimeError("Database configuration is not suitable for deployment (not thread-safe).")
49+
self.app.start_indexing()
4950
return BaseApplication.run(self)

0 commit comments

Comments
 (0)