mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Don't create new app instance for background tasks. Reuse the old one!
This commit is contained in:
parent
565d273dd4
commit
e658d2bbd0
@ -13,16 +13,12 @@ mail = Mail()
|
||||
socketio = SocketIO()
|
||||
|
||||
|
||||
def create_app(config_name, main=True):
|
||||
def create_app(config_name):
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config[config_name])
|
||||
|
||||
config[config_name].init_app(app)
|
||||
db.init_app(app)
|
||||
|
||||
if not main:
|
||||
return app
|
||||
|
||||
login_manager.init_app(app)
|
||||
mail.init_app(app)
|
||||
socketio.init_app(app, message_qeue='redis://')
|
||||
|
@ -1,6 +1,6 @@
|
||||
from flask import request
|
||||
from flask import current_app, request
|
||||
from flask_login import current_user, login_required
|
||||
from .. import create_app, db, socketio
|
||||
from .. import db, socketio
|
||||
from ..models import User
|
||||
import json
|
||||
import jsonpatch
|
||||
@ -23,6 +23,7 @@ def connect():
|
||||
' task associated with the sid.
|
||||
'''
|
||||
socketio.start_background_task(background_task,
|
||||
current_app._get_current_object(),
|
||||
current_user.id,
|
||||
request.sid)
|
||||
|
||||
@ -37,7 +38,7 @@ def disconnect():
|
||||
disconnected.append(request.sid)
|
||||
|
||||
|
||||
def background_task(user_id, session_id):
|
||||
def background_task(app, user_id, session_id):
|
||||
'''
|
||||
' Sends initial corpus and job lists to the client. Afterwards it checks
|
||||
' every 3 seconds if changes to the initial values appeared. If changes are
|
||||
@ -48,12 +49,6 @@ def background_task(user_id, session_id):
|
||||
'
|
||||
' > where '*' is either 'corpora' or 'jobs'
|
||||
'''
|
||||
'''
|
||||
' Create an app instance to get access to an app_context with which db
|
||||
' operations are fulfilled.
|
||||
'''
|
||||
app = create_app(os.getenv('FLASK_CONFIG') or 'default', main=False)
|
||||
|
||||
with app.app_context():
|
||||
user = db.session.query(User).filter_by(id=user_id).first()
|
||||
''' Get current values from the database. '''
|
||||
|
Loading…
Reference in New Issue
Block a user