diff --git a/analytics/analytics/analytic_unit_manager.py b/analytics/analytics/analytic_unit_manager.py index b2f028e..f97f6b0 100644 --- a/analytics/analytics/analytic_unit_manager.py +++ b/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) } diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index b82f7e5..894ba1d 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/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([