From 5aa777bc111230a39eb87c9cfcadeb9a77d1936c Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 6 Nov 2019 14:45:08 +0100 Subject: [PATCH] Set corpus analysis connection stop signal --- app/corpora/events.py | 12 ++++++++---- app/templates/corpora/corpus_analysis.html.j2 | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/corpora/events.py b/app/corpora/events.py index 9a7a5af1..51b240ac 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -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) - logger.warning('Stop container, stop!') + corpus = Corpus.query.filter_by(id=corpus_id).first() + corpus.status = 'stop analysis' + db.session.commit() + logger.warning('Stop container, stop!') diff --git a/app/templates/corpora/corpus_analysis.html.j2 b/app/templates/corpora/corpus_analysis.html.j2 index 33534038..39599272 100644 --- a/app/templates/corpora/corpus_analysis.html.j2 +++ b/app/templates/corpora/corpus_analysis.html.j2 @@ -2,7 +2,7 @@ {% block page_content %}