Browse Source

Don't run detection if learning failed #549 (#578)

pull/1/head
rozetko 6 years ago committed by GitHub
parent
commit
ead459ccb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      server/src/controllers/analytics_controller.ts
  2. 2
      server/src/routes/analytic_units_router.ts

8
server/src/controllers/analytics_controller.ts

@ -229,8 +229,9 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) {
} }
await AnalyticUnitCache.setData(id, result.payload.cache); await AnalyticUnitCache.setData(id, result.payload.cache);
} catch (err) { } catch (err) {
let message = err.message || JSON.stringify(err); const message = err.message || JSON.stringify(err);
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.FAILED, message); await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.FAILED, message);
throw new Error(message)
} }
} }
@ -429,9 +430,10 @@ export async function updateThreshold(
await Threshold.updateThreshold(id, value, condition); await Threshold.updateThreshold(id, value, condition);
} }
export async function runFirstLearning(id: AnalyticUnit.AnalyticUnitId) { export async function runLearningWithDetection(id: AnalyticUnit.AnalyticUnitId) {
// TODO: move setting status somehow "inside" learning // TODO: move setting status somehow "inside" learning
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.PENDING); await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.PENDING);
runLearning(id) runLearning(id)
.then(() => runDetect(id)); .then(() => runDetect(id))
.catch(err => console.error(err));
} }

2
server/src/routes/analytic_units_router.ts

@ -125,7 +125,7 @@ async function deleteUnit(ctx: Router.IRouterContext) {
async function runDetect(ctx: Router.IRouterContext) { async function runDetect(ctx: Router.IRouterContext) {
const { ids } = ctx.request.body as { ids: AnalyticUnit.AnalyticUnitId[] }; const { ids } = ctx.request.body as { ids: AnalyticUnit.AnalyticUnitId[] };
await Promise.all(ids.map(AnalyticsController.runFirstLearning)); await Promise.all(ids.map(AnalyticsController.runLearningWithDetection));
ctx.response.body = { ctx.response.body = {
code: 200, code: 200,

Loading…
Cancel
Save