Abort transmission after disconnect

This commit is contained in:
Patrick Jentsch 2020-03-30 09:01:40 +02:00
parent 0be0e12aee
commit 4556a52ffc

View File

@ -24,10 +24,6 @@ pj_corpus_analysis_clients = {}
@socketio.on('pj_corpus_analysis_init') @socketio.on('pj_corpus_analysis_init')
@socketio_login_required @socketio_login_required
def pj_init_corpus_analysis(corpus_id): def pj_init_corpus_analysis(corpus_id):
logger.warning(
'[{}] User {} > pj_corpus_analysis_init({})'.format(request.sid,
current_user.id,
corpus_id))
socketio.start_background_task(pj_corpus_analysis_session_handler, socketio.start_background_task(pj_corpus_analysis_session_handler,
current_app._get_current_object(), current_app._get_current_object(),
corpus_id, current_user.id, request.sid) corpus_id, current_user.id, request.sid)
@ -36,10 +32,6 @@ def pj_init_corpus_analysis(corpus_id):
@socketio.on('pj_corpus_analysis_query') @socketio.on('pj_corpus_analysis_query')
@socketio_login_required @socketio_login_required
def pj_corpus_analysis_query(query): def pj_corpus_analysis_query(query):
logger.warning(
'[{}] User {} > pj_corpus_analysis_query({})'.format(request.sid,
current_user.id,
query))
client = pj_corpus_analysis_clients.get(request.sid) client = pj_corpus_analysis_clients.get(request.sid)
if client is None: if client is None:
response = {'code': 404, 'desc': 'No client found for this session', response = {'code': 404, 'desc': 'No client found for this session',
@ -84,6 +76,7 @@ def pj_corpus_analysis_query(query):
client.status = 'running' client.status = 'running'
while chunk_start <= results.size: while chunk_start <= results.size:
logger.warning(client.status) logger.warning(client.status)
print(client.status)
if client.status == 'abort': if client.status == 'abort':
break break
chunk = results.export(context=context, cutoff=chunk_size, chunk = results.export(context=context, cutoff=chunk_size,
@ -145,6 +138,10 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
while session_id in connected_sessions: while session_id in connected_sessions:
socketio.sleep(3) socketio.sleep(3)
''' Teardown analysis session ''' ''' Teardown analysis session '''
if client.status == 'running':
client.status = 'abort'
while client.status != 'ready':
socketio.sleep(0.1)
try: try:
client.disconnect() client.disconnect()
except cqi.errors.CQiException: except cqi.errors.CQiException: