Browse Source

Log all analytics errors #353 (#356)

* Return error when analytics is not ready

* Log handle_analytic_task exception

* Return error on detection failure
pull/1/head
rozetko 6 years ago committed by Alexey Velikiy
parent
commit
8d98007fec
  1. 3
      analytics/analytics/analytic_unit_manager.py
  2. 23
      server/src/controllers/analytics_controller.ts

3
analytics/analytics/analytic_unit_manager.py

@ -98,8 +98,9 @@ class AnalyticUnitManager:
return result_message
except Exception as e:
error_text = traceback.format_exc()
logger.error("handle_analytic_task Exception: '%s'" % error_text)
# TODO: move result to a class which renders to json for messaging to analytics
return {
'status': 'FAILED',
'error': str(e)
'error': repr(e)
}

23
server/src/controllers/analytics_controller.ts

@ -168,6 +168,10 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) {
throw new Error('Can`t start learning when it`s already started [' + id + ']');
}
if(!isAnalyticReady()) {
throw new Error('Analytics is not ready');
}
let oldCache = await AnalyticUnitCache.findById(id);
if(oldCache !== null) {
oldCache = oldCache.data;
@ -205,7 +209,7 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) {
console.debug(`run task, id:${id}`);
let result = await runTask(task);
if(result.status !== AnalyticUnit.AnalyticUnitStatus.SUCCESS) {
throw new Error(result.error)
throw new Error(result.error);
}
await AnalyticUnitCache.setData(id, result.payload.cache);
} catch (err) {
@ -219,6 +223,10 @@ export async function runDetect(id: AnalyticUnit.AnalyticUnitId) {
let previousLastDetectionTime: number = undefined;
try {
if(!isAnalyticReady()) {
throw new Error('Analytics is not ready');
}
let unit = await AnalyticUnit.findById(id);
previousLastDetectionTime = unit.lastDetectionTime;
let analyticUnitType = unit.type;
@ -240,22 +248,11 @@ export async function runDetect(id: AnalyticUnit.AnalyticUnitId) {
console.debug(`run task, id:${id}`);
let result = await runTask(task);
if(result.status === AnalyticUnit.AnalyticUnitStatus.FAILED) {
return [];
throw new Error(result.error);
}
let payload = await processDetectionResult(id, result.payload);
// TODO: implement segments merging without removing labeled
// if(segments.length > 0 && payload.segments.length > 0) {
// let lastOldSegment = segments[segments.length - 1];
// let firstNewSegment = payload.segments[0];
// if(firstNewSegment.from <= lastOldSegment.to) {
// payload.segments[0].from = lastOldSegment.from;
// Segment.removeSegments([lastOldSegment.id])
// }
// }
await deleteNonDetectedSegments(id, payload);
await Promise.all([

Loading…
Cancel
Save