mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Fix issues in cqi_over_sio
This commit is contained in:
parent
efa8712cd9
commit
07103ee4e5
@ -84,7 +84,7 @@ def connect(auth):
|
|||||||
retry_counter -= 1
|
retry_counter -= 1
|
||||||
db.session.refresh(corpus)
|
db.session.refresh(corpus)
|
||||||
cqi_client = CQiClient(f'cqpserver_{corpus_id}')
|
cqi_client = CQiClient(f'cqpserver_{corpus_id}')
|
||||||
session['d'] = {
|
session['cqi_over_sio'] = {
|
||||||
'corpus_id': corpus_id,
|
'corpus_id': corpus_id,
|
||||||
'cqi_client': cqi_client,
|
'cqi_client': cqi_client,
|
||||||
'cqi_client_lock': Lock(),
|
'cqi_client_lock': Lock(),
|
||||||
@ -94,16 +94,19 @@ def connect(auth):
|
|||||||
|
|
||||||
@socketio.on('disconnect', namespace=NAMESPACE)
|
@socketio.on('disconnect', namespace=NAMESPACE)
|
||||||
def disconnect():
|
def disconnect():
|
||||||
if 'd' not in session:
|
|
||||||
return
|
|
||||||
session['d']['cqi_client_lock'].acquire()
|
|
||||||
try:
|
try:
|
||||||
session['d']['cqi_client'].api.ctrl_bye()
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
|
cqi_client_lock: Lock = session['cqi_over_sio']['cqi_client_lock']
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
cqi_client_lock.acquire()
|
||||||
|
try:
|
||||||
|
cqi_client.api.ctrl_bye()
|
||||||
except (BrokenPipeError, CQiException):
|
except (BrokenPipeError, CQiException):
|
||||||
pass
|
pass
|
||||||
session['d']['cqi_client_lock'].release()
|
cqi_client_lock.release()
|
||||||
corpus = Corpus.query.get(session['d']['corpus_id'])
|
corpus = Corpus.query.get(session['cqi_over_sio']['corpus_id'])
|
||||||
corpus.num_analysis_sessions = Corpus.num_analysis_sessions - 1
|
corpus.num_analysis_sessions = Corpus.num_analysis_sessions - 1
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
session.pop('d')
|
session.pop('cqi_over_sio')
|
||||||
# return {'code': 200, 'msg': 'OK'}
|
# return {'code': 200, 'msg': 'OK'}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
from cqi import APIClient
|
from cqi import CQiClient
|
||||||
from cqi.errors import CQiException
|
from cqi.errors import CQiException
|
||||||
from cqi.status import CQiStatus
|
from cqi.status import CQiStatus
|
||||||
from flask import session
|
from flask import session
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
|
from threading import Lock
|
||||||
from typing import Callable, Dict, List
|
from typing import Callable, Dict, List
|
||||||
from app import socketio
|
from app import socketio
|
||||||
from app.decorators import socketio_login_required
|
from app.decorators import socketio_login_required
|
||||||
@ -60,18 +61,20 @@ CQI_API_FUNCTIONS: List[str] = [
|
|||||||
@socketio.on('cqi_client.api', namespace=ns)
|
@socketio.on('cqi_client.api', namespace=ns)
|
||||||
@socketio_login_required
|
@socketio_login_required
|
||||||
def cqi_over_sio(fn_data):
|
def cqi_over_sio(fn_data):
|
||||||
|
try:
|
||||||
|
fn_name: str = fn_data['fn_name']
|
||||||
|
if fn_name not in CQI_API_FUNCTIONS:
|
||||||
|
raise KeyError
|
||||||
|
except KeyError:
|
||||||
|
return {'code': 400, 'msg': 'Bad Request'}
|
||||||
fn_name: str = fn_data['fn_name']
|
fn_name: str = fn_data['fn_name']
|
||||||
fn_args: Dict = fn_data.get('fn_args', {})
|
fn_args: Dict = fn_data.get('fn_args', {})
|
||||||
print(f'{fn_name}({fn_args})')
|
|
||||||
if 'd' not in session:
|
|
||||||
return {'code': 424, 'msg': 'Failed Dependency'}
|
|
||||||
api_client: APIClient = session['d']['cqi_client'].api
|
|
||||||
if fn_name not in CQI_API_FUNCTIONS:
|
|
||||||
return {'code': 400, 'msg': 'Bad Request'}
|
|
||||||
try:
|
try:
|
||||||
fn: Callable = getattr(api_client, fn_name)
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
except AttributeError:
|
cqi_client_lock: Lock = session['cqi_over_sio']['cqi_client_lock']
|
||||||
return {'code': 400, 'msg': 'Bad Request'}
|
except KeyError:
|
||||||
|
return {'code': 424, 'msg': 'Failed Dependency'}
|
||||||
|
fn: Callable = getattr(cqi_client.api, fn_name)
|
||||||
for param in signature(fn).parameters.values():
|
for param in signature(fn).parameters.values():
|
||||||
if param.default is param.empty:
|
if param.default is param.empty:
|
||||||
if param.name not in fn_args:
|
if param.name not in fn_args:
|
||||||
@ -81,7 +84,7 @@ def cqi_over_sio(fn_data):
|
|||||||
continue
|
continue
|
||||||
if type(fn_args[param.name]) is not param.annotation:
|
if type(fn_args[param.name]) is not param.annotation:
|
||||||
return {'code': 400, 'msg': 'Bad Request'}
|
return {'code': 400, 'msg': 'Bad Request'}
|
||||||
session['d']['cqi_client_lock'].acquire()
|
cqi_client_lock.acquire()
|
||||||
try:
|
try:
|
||||||
return_value = fn(**fn_args)
|
return_value = fn(**fn_args)
|
||||||
except BrokenPipeError:
|
except BrokenPipeError:
|
||||||
@ -100,7 +103,7 @@ def cqi_over_sio(fn_data):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally:
|
finally:
|
||||||
session['d']['cqi_client_lock'].release()
|
cqi_client_lock.release()
|
||||||
if isinstance(return_value, CQiStatus):
|
if isinstance(return_value, CQiStatus):
|
||||||
payload = {
|
payload = {
|
||||||
'code': return_value.code,
|
'code': return_value.code,
|
||||||
|
@ -40,21 +40,21 @@ cqi.models.corpora.Corpus = class Corpus extends cqi.models.resource.Model {
|
|||||||
/**
|
/**
|
||||||
* @returns {cqi.models.attributes.AlignmentAttributeCollection}
|
* @returns {cqi.models.attributes.AlignmentAttributeCollection}
|
||||||
*/
|
*/
|
||||||
get alignment_attributes() {
|
get alignmentAttributes() {
|
||||||
return new cqi.models.attributes.AlignmentAttributeCollection(this.client, this);
|
return new cqi.models.attributes.AlignmentAttributeCollection(this.client, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {cqi.models.attributes.PositionalAttributeCollection}
|
* @returns {cqi.models.attributes.PositionalAttributeCollection}
|
||||||
*/
|
*/
|
||||||
get positional_attributes() {
|
get positionalAttributes() {
|
||||||
return new cqi.models.attributes.PositionalAttributeCollection(this.client, this);
|
return new cqi.models.attributes.PositionalAttributeCollection(this.client, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {cqi.models.attributes.StructuralAttributeCollection}
|
* @returns {cqi.models.attributes.StructuralAttributeCollection}
|
||||||
*/
|
*/
|
||||||
get structural_attributes() {
|
get structuralAttributes() {
|
||||||
return new cqi.models.attributes.StructuralAttributeCollection(this.client, this);
|
return new cqi.models.attributes.StructuralAttributeCollection(this.client, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user