Set corpus analysis connection stop signal

This commit is contained in:
Patrick Jentsch 2019-11-06 14:45:08 +01:00
parent 1389b6b510
commit 5aa777bc11
2 changed files with 9 additions and 5 deletions

View File

@ -1,5 +1,6 @@
from app import socketio
from app import db, socketio
from app.events import connected_sessions
from app.models import Corpus
from flask import current_app, request
from flask_login import login_required
import logging
@ -9,7 +10,7 @@ import logging
@login_required
def init_corpus_analysis(corpus_id):
''' TODO: Check if current_user is allowed to subscribe to this '''
socketio.start_background_task(init_corpus_analysis_,
socketio.start_background_task(observe_corpus_analysis_connection,
current_app._get_current_object(),
corpus_id,
request.sid)
@ -21,10 +22,13 @@ def recv_query(message):
logger.warning(message)
def init_corpus_analysis_(app, corpus_id, session_id):
def observe_corpus_analysis_connection(app, corpus_id, session_id):
logger = logging.getLogger(__name__)
with app.app_context():
while session_id in connected_sessions:
logger.warning('Run container, run!')
socketio.sleep(3)
corpus = Corpus.query.filter_by(id=corpus_id).first()
corpus.status = 'stop analysis'
db.session.commit()
logger.warning('Stop container, stop!')

View File

@ -2,7 +2,7 @@
{% block page_content %}
<script>
socket.emit('init_corpus_analysis', {{ corpus.id }});
socket.emit('init_corpus_analysis', {{ corpus_id }});
</script>