forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split redash/__init__.py to prevent import time side-effects. (getred…
…ash#3601) ## What type of PR is this? (check all applicable) <!-- Please leave only what's applicable --> - [x] Refactor - [x] Bug Fix ## Description This basically makes sure that when import the redash package we don't accidentally trigger import-time side-effects such as requiring Redis. Refs getredash#3569 and getredash#3466.
- Loading branch information
1 parent
f437081
commit 12a824b
Showing
8 changed files
with
82 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from flask import Flask | ||
from werkzeug.contrib.fixers import ProxyFix | ||
|
||
from . import settings | ||
|
||
|
||
class Redash(Flask): | ||
"""A custom Flask app for Redash""" | ||
def __init__(self, *args, **kwargs): | ||
kwargs.update({ | ||
'template_folder': settings.STATIC_ASSETS_PATH, | ||
'static_folder': settings.STATIC_ASSETS_PATH, | ||
'static_path': '/static', | ||
}) | ||
super(Redash, self).__init__(__name__, *args, **kwargs) | ||
# Make sure we get the right referral address even behind proxies like nginx. | ||
self.wsgi_app = ProxyFix(self.wsgi_app, settings.PROXIES_COUNT) | ||
# Configure Redash using our settings | ||
self.config.from_object('redash.settings') | ||
|
||
|
||
def create_app(): | ||
from . import authentication, extensions, handlers, limiter, mail, migrate, security | ||
from .destinations import import_destinations | ||
from .handlers import chrome_logger | ||
from .handlers.webpack import configure_webpack | ||
from .metrics import request as request_metrics | ||
from .models import db, users | ||
from .query_runner import import_query_runners | ||
from .utils import sentry | ||
from .version_check import reset_new_version_status | ||
|
||
sentry.init() | ||
app = Redash() | ||
|
||
# Check and update the cached version for use by the client | ||
app.before_first_request(reset_new_version_status) | ||
|
||
# Load query runners and destinations | ||
import_query_runners(settings.QUERY_RUNNERS) | ||
import_destinations(settings.DESTINATIONS) | ||
|
||
security.init_app(app) | ||
request_metrics.init_app(app) | ||
db.init_app(app) | ||
migrate.init_app(app, db) | ||
mail.init_app(app) | ||
authentication.init_app(app) | ||
limiter.init_app(app) | ||
handlers.init_app(app) | ||
configure_webpack(app) | ||
extensions.init_app(app) | ||
chrome_logger.init_app(app) | ||
users.init_app(app) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters