diff --git a/knowledge_repo/app/index.py b/knowledge_repo/app/index.py index 43da1afc4..9dafed1d3 100644 --- a/knowledge_repo/app/index.py +++ b/knowledge_repo/app/index.py @@ -15,6 +15,8 @@ LOCKED = CHECKED = '1' UNLOCKED = '0' +sync_lock = multiprocessing.Lock() + def set_up_indexing_timers(app): if not app.config['INDEXING_ENABLED']: @@ -39,9 +41,12 @@ def index_watchdog(app): def index_sync_loop(app): current_app.db.engine.dispose() while True: - with app.app_context(): - update_index(check_timeouts=False) - time.sleep(app.config['INDEXING_INTERVAL']) + sync_lock.acquire() + try: + with app.app_context(): + update_index(check_timeouts=False) + finally: + sync_lock.release() app.index_watchdog = multiprocessing.Process(target=index_watchdog, args=(app,)) app.index_watchdog.start()