Skip to content
Snippets Groups Projects
Commit ebf2f00e authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Add example for client management

parent 3ccae085
No related branches found
No related tags found
No related merge requests found
...@@ -8,12 +8,14 @@ import logging ...@@ -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): ...@@ -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!')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment