@app.teardown_request def _teardown_request(unused_exception=None): total_duration = time.time() - flask.g.start if total_duration <= _LONG_REQUEST_DURATION_SECONDS: return logging.warning('Long request: %d seconds', total_duration) last_tick_time = flask.g.start for tick in sorted(flask.g.ticks, key=lambda t: t.time): logging.warning('%.4f: Tick %s (%.4f since last tick)', tick.time - flask.g.start, tick.name, tick.time - last_tick_time) last_tick_time = tick.time app.config['DATABASE'] = _DB if os.getenv('SENTRY_DSN'): raven_flask.Sentry(app, dsn=os.getenv('SENTRY_DSN'), logging=True, level=logging.WARNING) if __name__ == '__main__': # This is only used for dev setup as otherwise we use uwsgi that loads the # module and handle the server without running the app. app.run( # pragma: no cover debug=bool(os.getenv('DEBUG')), host=os.getenv('BIND_HOST', 'localhost'), port=int(os.getenv('PORT', '80')))
"""Application.""" from raven.contrib import flask from timed_release import api from timed_release import config from timed_release import handlers # noqa if config.SENTRY: api.app.config['SENTRY_DSN'] = config.SENTRY flask.Sentry(api.app) app = api.app
import warnings from flask import current_app, g import flask_sqlalchemy from flask_babel import Babel, get_locale from flask_wtf.csrf import CsrfProtect import six from sqlalchemy.engine import Engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.schema import MetaData from werkzeug.utils import import_string from .transformers import Transformer from .versioned_static import static_file, VersionedStaticFlask try: import raven.contrib.flask as raven_flask sentry = raven_flask.Sentry() except ImportError: sentry = None db = flask_sqlalchemy.SQLAlchemy() # Patch Flask-SQLAlchemy to use a custom Metadata instance with a naming scheme # for constraints. def _patch_metadata(): naming_convention = { 'fk': ('fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s' '_%(referred_column_0_name)s'), 'pk': 'pk_%(table_name)s', 'ix': 'ix_%(table_name)s_%(column_0_name)s', 'ck': 'ck_%(table_name)s_%(constraint_name)s', 'uq': 'uq_%(table_name)s_%(column_0_name)s',
def __init__(self, app=None): super(FlaskSentry, self).__init__() self.__sentry = flask.Sentry(app, client=super(FlaskSentry, self).client)
from flask_dance.contrib.github import github from flask_dance.contrib.github import make_github_blueprint from raven.contrib import flask as sentry_flask APP_PATH = os.environ.get('APP_PATH', os.path.dirname(os.path.abspath(__file__))) SENTRY_DSN = os.environ.get('SENTRY_DSN', None) app = flask.Flask(__name__) if SENTRY_DSN: sentry = sentry_flask.Sentry(app, dsn=SENTRY_DSN) app.config['PREFERRED_URL_SCHEME'] = 'https' app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'secret') app.config['FLASK_ENV'] = os.environ.get('FLASK_ENV', 'production') app.config['GITHUB_OAUTH_CLIENT_ID'] = \ os.environ.get('GITHUB_OAUTH_CLIENT_ID') app.config['GITHUB_OAUTH_CLIENT_SECRET'] = \ os.environ.get('GITHUB_OAUTH_CLIENT_SECRET') router = flask.Blueprint('router', __name__) ws = flask.Blueprint('ws', __name__) oauth = make_github_blueprint()