diff options
author | Muriithi Frederick Muriuki | 2018-01-30 13:07:58 +0300 |
---|---|---|
committer | Muriithi Frederick Muriuki | 2018-01-30 13:07:58 +0300 |
commit | afaea1b1297d0cf08565746799d2900a6981823a (patch) | |
tree | a10232b77ff3e49b309a6af9db9d9fc5fac76a0a /wqflask/utility/elasticsearch_tools.py | |
parent | fb0ad54313366a3f0efda3ef20e800d5e52d1d53 (diff) | |
download | genenetwork2-afaea1b1297d0cf08565746799d2900a6981823a.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.py | 16 |
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 |