small updates

This commit is contained in:
Patrick Jentsch 2020-03-29 20:33:00 +02:00
parent d07b73781f
commit 4ff372de77
2 changed files with 13 additions and 4 deletions

View File

@ -1,7 +1,8 @@
from flask import current_app, request
from flask_login import current_user
from socket import gaierror
from . import cqi
from .. import db, socketio
from .. import db, logger, socketio
from ..decorators import socketio_login_required
from ..events import connected_sessions
from ..models import Corpus, User
@ -93,7 +94,7 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
socketio.sleep(3)
client = cqi.CQiClient('corpus_{}_analysis'.format(corpus_id))
try:
client.connect()
connect_status = client.connect()
except cqi.errors.CQiException as e:
response = {'code': 500, 'desc': None,
'msg': 'Internal Server Error',
@ -101,12 +102,18 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
'msg': e.name}}
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
return
except gaierror:
response = {'code': 500, 'desc': None,
'msg': 'Internal Server Error'}
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
return
pj_corpus_analysis_clients[session_id] = client
if corpus_id not in pj_corpus_analysis_sessions:
pj_corpus_analysis_sessions[corpus_id] = [session_id]
else:
pj_corpus_analysis_sessions[corpus_id].append(session_id)
response = {'code': 200, 'desc': None, 'msg': 'OK'}
response = {'code': 200, 'desc': None, 'msg': 'OK',
'payload': {**connect_status}}
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
''' Observe analysis session '''
while session_id in connected_sessions:

View File

@ -6,12 +6,14 @@ class CorpusAnalysisClient {
this.socket = socket;
socket.on("pj_corpus_analysis_init", (response) => {
var errorText;
if (response.code === 200) {
console.log(`pj_corpus_analysis_init: ${response.code} - ${response.msg}`);
if (this.callbacks.init != undefined) {this.callbacks.init(response.payload);}
if (this.displays.init != undefined) {this.displays.init.setVisibilityByStatus("success");}
} else {
errorText = `Error ${response.payload.code} - ${response.payload.msg}`;
errorText = `Error ${response.code} - ${response.msg}`;
if (this.displays.init.errorContainer != undefined) {this.displays.init.errorContainer.innerHTML = `<p class="red-text"><i class="material-icons tiny">error</i> ${errorText}</p>`;}
if (this.displays.init != undefined) {this.displays.init.setVisibilityByStatus("error");}
console.error(`pj_corpus_analysis_init: ${errorText}`);