tuning import process and db handling
This commit is contained in:
+15
-1
@@ -18,6 +18,21 @@ def create_app(config_class='config.Config'):
|
||||
login_manager.init_app(app)
|
||||
login_manager.login_view = 'auth.login'
|
||||
|
||||
with app.app_context():
|
||||
# Enable connection ping only for PostgreSQL
|
||||
if app.config['SQLALCHEMY_DATABASE_URI'].startswith("postgresql"):
|
||||
from sqlalchemy import event, text
|
||||
from sqlalchemy.exc import DisconnectionError
|
||||
|
||||
@event.listens_for(db.engine, "engine_connect")
|
||||
def ping_connection(connection, branch):
|
||||
if branch:
|
||||
return
|
||||
try:
|
||||
connection.execution_options(isolation_level="AUTOCOMMIT").scalar(text("SELECT 1"))
|
||||
except:
|
||||
raise DisconnectionError()
|
||||
|
||||
from app.main import main
|
||||
from app.auth import auth
|
||||
|
||||
@@ -28,5 +43,4 @@ def create_app(config_class='config.Config'):
|
||||
def datetimeformat(value, format="%Y-%m-%d"):
|
||||
return value.strftime(format) if value else ""
|
||||
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user