mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +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_login_required
|
||||
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,
|
||||
current_app._get_current_object(),
|
||||
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_login_required
|
||||
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)
|
||||
if client is None:
|
||||
response = {'code': 404, 'desc': 'No client found for this session',
|
||||
'msg': 'Failed Dependency'}
|
||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
||||
return
|
||||
if client.status == 'running':
|
||||
client.status = 'abort'
|
||||
while client.status != 'ready':
|
||||
socketio.sleep(0.1)
|
||||
try:
|
||||
corpus = client.corpora.get('CORPUS')
|
||||
except cqi.errors.CQiException as e:
|
||||
@ -69,7 +81,11 @@ def pj_corpus_analysis_query(query):
|
||||
chunk_start = 0
|
||||
context = 100
|
||||
progress = 0
|
||||
client.status = 'running'
|
||||
while chunk_start <= results.size:
|
||||
logger.warning(client.status)
|
||||
if client.status == 'abort':
|
||||
break
|
||||
chunk = results.export(context=context, cutoff=chunk_size,
|
||||
offset=chunk_start)
|
||||
if (results.size == 0):
|
||||
@ -82,6 +98,7 @@ def pj_corpus_analysis_query(query):
|
||||
socketio.emit('pj_corpus_analysis_query_results', response,
|
||||
room=request.sid)
|
||||
chunk_start += chunk_size
|
||||
client.status = 'ready'
|
||||
|
||||
|
||||
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]
|
||||
else:
|
||||
pj_corpus_analysis_sessions[corpus_id].append(session_id)
|
||||
client.status = 'ready'
|
||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||
'payload': {**connect_status}}
|
||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
||||
|
Loading…
Reference in New Issue
Block a user