diff --git a/superset/__init__.py b/superset/__init__.py index 099edc133e15..943f7b4ca304 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -153,6 +153,21 @@ def index(self): sm = appbuilder.sm +before_request_functions = conf.get('BEFORE_REQUEST_FUNCTIONS') + + +@app.before_request +def before_request(): + for f in before_request_functions: + try: + f() + except Exception as e: + print( + 'Exception {} in before_request function {}' + .format(e, f.func_name)) + logging.exception(e) + + results_backend = app.config.get('RESULTS_BACKEND') # Registering sources diff --git a/superset/config.py b/superset/config.py index 8f9058badacd..cbf36b41de64 100644 --- a/superset/config.py +++ b/superset/config.py @@ -322,6 +322,8 @@ class CeleryConfig(object): CONFIG_PATH_ENV_VAR = 'SUPERSET_CONFIG_PATH' +# List of functions that are executed before every request. Order may matter. +BEFORE_REQUEST_FUNCTIONS = [] # smtp server configuration EMAIL_NOTIFICATIONS = False # all the emails are sent using dryrun