mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-04-06 01:04:22 +00:00
add simple status check
This commit is contained in:
parent
6e3579b33f
commit
0be0e12aee
@ -24,6 +24,10 @@ 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)
|
||||||
@ -32,12 +36,20 @@ 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',
|
||||||
'msg': 'Failed Dependency'}
|
'msg': 'Failed Dependency'}
|
||||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
return
|
||||||
|
if client.status == 'running':
|
||||||
|
client.status = 'abort'
|
||||||
|
while client.status != 'ready':
|
||||||
|
socketio.sleep(0.1)
|
||||||
try:
|
try:
|
||||||
corpus = client.corpora.get('CORPUS')
|
corpus = client.corpora.get('CORPUS')
|
||||||
except cqi.errors.CQiException as e:
|
except cqi.errors.CQiException as e:
|
||||||
@ -69,7 +81,11 @@ def pj_corpus_analysis_query(query):
|
|||||||
chunk_start = 0
|
chunk_start = 0
|
||||||
context = 100
|
context = 100
|
||||||
progress = 0
|
progress = 0
|
||||||
|
client.status = 'running'
|
||||||
while chunk_start <= results.size:
|
while chunk_start <= results.size:
|
||||||
|
logger.warning(client.status)
|
||||||
|
if client.status == 'abort':
|
||||||
|
break
|
||||||
chunk = results.export(context=context, cutoff=chunk_size,
|
chunk = results.export(context=context, cutoff=chunk_size,
|
||||||
offset=chunk_start)
|
offset=chunk_start)
|
||||||
if (results.size == 0):
|
if (results.size == 0):
|
||||||
@ -82,6 +98,7 @@ def pj_corpus_analysis_query(query):
|
|||||||
socketio.emit('pj_corpus_analysis_query_results', response,
|
socketio.emit('pj_corpus_analysis_query_results', response,
|
||||||
room=request.sid)
|
room=request.sid)
|
||||||
chunk_start += chunk_size
|
chunk_start += chunk_size
|
||||||
|
client.status = 'ready'
|
||||||
|
|
||||||
|
|
||||||
def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
||||||
@ -120,6 +137,7 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
|||||||
pj_corpus_analysis_sessions[corpus_id] = [session_id]
|
pj_corpus_analysis_sessions[corpus_id] = [session_id]
|
||||||
else:
|
else:
|
||||||
pj_corpus_analysis_sessions[corpus_id].append(session_id)
|
pj_corpus_analysis_sessions[corpus_id].append(session_id)
|
||||||
|
client.status = 'ready'
|
||||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||||
'payload': {**connect_status}}
|
'payload': {**connect_status}}
|
||||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user