mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Add example for client management
This commit is contained in:
parent
3ccae085d2
commit
ebf2f00e0d
@ -8,12 +8,14 @@ import logging
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
analysis_clients = {}
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('init_corpus_analysis')
|
@socketio.on('init_corpus_analysis')
|
||||||
@login_required
|
@login_required
|
||||||
def init_corpus_analysis(corpus_id):
|
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 '''
|
''' 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,
|
socketio.start_background_task(observe_corpus_analysis_connection,
|
||||||
current_app._get_current_object(),
|
current_app._get_current_object(),
|
||||||
corpus_id,
|
corpus_id,
|
||||||
@ -24,20 +26,20 @@ def init_corpus_analysis(corpus_id):
|
|||||||
def recv_query(message):
|
def recv_query(message):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.warning(message)
|
logger.warning(message)
|
||||||
|
analysis_client = analysis_clients[request.sid]
|
||||||
|
|
||||||
|
|
||||||
def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
time.sleep(5) # wait for IP of container only for dev
|
|
||||||
corpus = Corpus.query.filter_by(id=corpus_id).first()
|
corpus = Corpus.query.filter_by(id=corpus_id).first()
|
||||||
logger.warning('IP adress is: {}'.format(corpus.analysis_container_ip))
|
logger.warning('MÖÖÖÖP')
|
||||||
cqi_client = CQiClient(host=corpus.analysis_container_ip)
|
analysis_client = CQiClient(host=corpus.analysis_container_ip)
|
||||||
cqi_client.ctrl_connect('opaque', 'opaque')
|
analysis_client.ctrl_connect('opaque', 'opaque')
|
||||||
|
analysis_clients[session_id] = analysis_client
|
||||||
while session_id in connected_sessions:
|
while session_id in connected_sessions:
|
||||||
logger.warning(cqi_client.ctrl_ping())
|
logger.warning(analysis_client.ctrl_ping())
|
||||||
logger.warning('Run container, run!')
|
|
||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
|
analysis_client.ctrl_bye()
|
||||||
corpus.status = 'stop analysis'
|
corpus.status = 'stop analysis'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
logger.warning('Stop container, stop!')
|
|
||||||
|
Loading…
Reference in New Issue
Block a user