Add checkers in threads
An attempt to solve #8. Instead of going with async, I tried to keep things in threads, as Flask (for example) does not use async and that would not work (how would one run an event loop on each thread?).
Also, I did some reorganization on the files, as (AFAIK) the default requirements files are called requirements.txt and requirements-dev.txt (again, AFAIK, but there is nothing forcing to use that name).
It is braking ateliedocodigo/eve-healthcheck, cause it shares database connection pool with health check
[2019-10-09 13:03:01,787] ERROR:healthcheck.healthcheck:73 - module 'eve' has no attribute 'SOURCES'
Traceback (most recent call last):
File "/src/api/venv/lib/python3.5/site-packages/eve/utils.py", line 37, in __getattr__
return app.config.get(name)
File "/src/api/venv/lib/python3.5/site-packages/werkzeug/local.py", line 343, in __getattr__
return getattr(self._get_current_object(), name)
File "/src/api/venv/lib/python3.5/site-packages/werkzeug/local.py", line 302, in _get_current_object
return self.__local()
File "/src/api/venv/lib/python3.5/site-packages/flask/globals.py", line 51, in _find_app
raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.
As documented here, a possible solution is use flask app context like:
def check_wrapper(app):
def database_check():
with app.app_context():
# perform a count
con = app.db.connect()
if not:
return False, "Database NOK"
return True, "Database OK"
return database_check
The secret here is the app context, that needs to be used as app.app_context(). The problem is that this library should work with flask and tornado, so it needs to be generic