mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 02:24:20 +00:00
Add example for client management
This commit is contained in:
parent
3ccae085d2
commit
ebf2f00e0d
@ -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!')
|
||||
|
Loading…
Reference in New Issue
Block a user