From 690e525a8a063d1be107c15521474052bd6ae2b4 Mon Sep 17 00:00:00 2001
From: Muriithi Frederick Muriuki
Date: Fri, 9 Feb 2018 11:02:07 +0300
Subject: Check elasticsearch at point of use

* Instead of checking for the state of elasticsearch at startup, check
  the state at the moment the user requests a feature that depends on
  elasticsearch.
  This reduces the chances that the user is dropped onto an exception
  page when elasticsearch server goes down.
---
 wqflask/utility/elasticsearch_tools.py | 3 ---
 wqflask/wqflask/user_manager.py        | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index a0383033..4fc0035c 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -8,9 +8,6 @@ try:
         , "port": ELASTICSEARCH_PORT
     }]) if (ELASTICSEARCH_HOST and ELASTICSEARCH_PORT) else None
 
-    # Check if elasticsearch is running
-    if not es.ping():
-        es = None
 except:
     es = None
 
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index 8f09c206..630be9aa 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -626,7 +626,7 @@ class LoginUser(object):
             return render_template(
                 "new_security/login_user.html"
                 , external_login=external_login
-                , es_server=es)
+                , es_server=es.ping())
         else:
             user_details = get_user_by_unique_column("email_address", params["email_address"])
             user = None
-- 
cgit v1.2.3