mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 03:14:19 +00:00
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
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
|
|
from .CQiClient.CQiClient import CQiClient
|
|
import logging
|
|
import time
|
|
|
|
|
|
@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 '''
|
|
socketio.start_background_task(observe_corpus_analysis_connection,
|
|
current_app._get_current_object(),
|
|
corpus_id,
|
|
request.sid)
|
|
|
|
|
|
@socketio.on('query_event')
|
|
def recv_query(message):
|
|
logger = logging.getLogger(__name__)
|
|
logger.warning(message)
|
|
|
|
|
|
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')
|
|
while session_id in connected_sessions:
|
|
logger.warning(cqi_client.ctrl_ping())
|
|
logger.warning('Run container, run!')
|
|
socketio.sleep(3)
|
|
corpus.status = 'stop analysis'
|
|
db.session.commit()
|
|
logger.warning('Stop container, stop!')
|