aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/elasticsearch_tools.py
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2018-01-30 13:07:58 +0300
committerPjotr Prins2018-03-26 09:24:35 +0000
commite0295504fb0097db394e99568339e24a71406123 (patch)
tree09fc1b0505c479fc6be5a28e5a02e385bedde871 /wqflask/utility/elasticsearch_tools.py
parent3029ae6ffe66f083f02d35d39e09500f76977197 (diff)
downloadgenenetwork2-e0295504fb0097db394e99568339e24a71406123.tar.gz
Fail safely if elasticsearch is down or unconfigured
* If elasticsearch server is down, or the configuration variables are not provided at startup or in a configuration file, then do not allow the system to simply crash, but instead, inform the user that they cannot use the services that depend on elasticsearch to be running.
Diffstat (limited to 'wqflask/utility/elasticsearch_tools.py')
-rw-r--r--wqflask/utility/elasticsearch_tools.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index c2c999ea..8b8ad9cc 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -1,10 +1,14 @@
-from elasticsearch import Elasticsearch, TransportError
-from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
+es = None
+try:
+ from elasticsearch import Elasticsearch, TransportError
+ from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
-es = Elasticsearch([{
- "host": ELASTICSEARCH_HOST
- , "port": ELASTICSEARCH_PORT
-}])
+ es = Elasticsearch([{
+ "host": ELASTICSEARCH_HOST
+ , "port": ELASTICSEARCH_PORT
+ }]) if (ELASTICSEARCH_HOST and ELASTICSEARCH_PORT) else None
+except:
+ es = None
def get_user_by_unique_column(column_name, column_value):
user_details = None