diff --git a/app/corpora/events.py b/app/corpora/events.py index 36f9f34d..8ad98fd3 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -8,12 +8,14 @@ import logging import time +analysis_clients = {} + + @socketio.on('init_corpus_analysis') @login_required def init_corpus_analysis(corpus_id): - logger = logging.getLogger(__name__) - logger.warning('init_corpus_analysis') ''' TODO: Check if current_user is allowed to subscribe to this ''' + time.sleep(5) # wait for IP of container only for dev socketio.start_background_task(observe_corpus_analysis_connection, current_app._get_current_object(), corpus_id, @@ -24,20 +26,20 @@ def init_corpus_analysis(corpus_id): def recv_query(message): logger = logging.getLogger(__name__) logger.warning(message) + analysis_client = analysis_clients[request.sid] def observe_corpus_analysis_connection(app, corpus_id, session_id): logger = logging.getLogger(__name__) with app.app_context(): - time.sleep(5) # wait for IP of container only for dev corpus = Corpus.query.filter_by(id=corpus_id).first() - logger.warning('IP adress is: {}'.format(corpus.analysis_container_ip)) - cqi_client = CQiClient(host=corpus.analysis_container_ip) - cqi_client.ctrl_connect('opaque', 'opaque') + logger.warning('MÖÖÖÖP') + analysis_client = CQiClient(host=corpus.analysis_container_ip) + analysis_client.ctrl_connect('opaque', 'opaque') + analysis_clients[session_id] = analysis_client while session_id in connected_sessions: - logger.warning(cqi_client.ctrl_ping()) - logger.warning('Run container, run!') + logger.warning(analysis_client.ctrl_ping()) socketio.sleep(3) + analysis_client.ctrl_bye() corpus.status = 'stop analysis' db.session.commit() - logger.warning('Stop container, stop!')