microblog icon indicating copy to clipboard operation
microblog copied to clipboard

Verify if elastic server is running

Open JulianHysi opened this issue 4 years ago • 3 comments

Hi Miguel,

I have a suggestion: in the application factory, check not only for the elastic env variable, but also if the elastic server is actually running.

The code extract from my own project:

if app.config['ELASTICSEARCH_URL']: es = Elasticsearch([app.config['ELASTICSEARCH_URL']]) app.elasticsearch = es if es.ping() else None else: app.elasticsearch = None

JulianHysi avatar Mar 25 '21 11:03 JulianHysi

Looks like Github didn't preserve the code indentation, so here's a picture of it:

image

JulianHysi avatar Mar 25 '21 11:03 JulianHysi

This is fine, but if the application is configured to use elasticsearch I think it is better that errors are generated, which will alert you that you have an issue with elasticsearch, instead of silently disabling all the search functionality.

miguelgrinberg avatar Mar 25 '21 15:03 miguelgrinberg

I see your point. In my case I have modified also the search() route function, where I do an abort(500) if elasticsearch attribute is set to None. This way it is clear that something went wrong, and no low level detail is exposed.

JulianHysi avatar Mar 25 '21 16:03 JulianHysi