Browse Source

Return analytic status #71

pull/1/head
Alexey Velikiy 6 years ago
parent
commit
811ffb7d5f
  1. 4
      server/src/controllers/analytics_controller.ts
  2. 8
      server/src/index.ts
  3. 10
      server/src/services/analytics_service.ts

4
server/src/controllers/analytics_controller.ts

@ -89,3 +89,7 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) {
AnalyticUnit.setPredictionTime(id, result.lastPredictionTime);
return result.segments;
}
export function isAnalyticReady(): boolean {
return analyticsService.ready;
}

8
server/src/index.ts

@ -2,6 +2,8 @@ import { router as anomaliesRouter } from './routes/analytic_units_router';
import { router as segmentsRouter } from './routes/segments_router';
import { router as alertsRouter } from './routes/alerts_router';
import * as AnalyticsController from './controllers/analytics_controller';
import * as Data from './services/data_service';
import { HASTIC_PORT } from './config';
@ -29,7 +31,11 @@ rootRouter.use('/analyticUnits', anomaliesRouter.routes(), anomaliesRouter.allow
rootRouter.use('/segments', segmentsRouter.routes(), segmentsRouter.allowedMethods());
rootRouter.use('/alerts', alertsRouter.routes(), alertsRouter.allowedMethods());
rootRouter.get('/', async (ctx) => {
ctx.response.body = { status: 'Ok' };
ctx.response.body = {
server: 'Ok',
analyticsReady: AnalyticsController.isAnalyticReady()
};
});
app

10
server/src/services/analytics_service.ts

@ -10,13 +10,17 @@ import * as path from 'path';
export class AnalyticsService {
private _requester: any;
private _ready: boolean = false;
constructor(private _onResponse: (response: any) => void) {
this._initConnection();
}
public async sendTask(msgObj: any): Promise<void> {
if(!this._ready) {
return Promise.reject("Analytics is not ready");
}
let message = JSON.stringify(msgObj);
return this.sendMessage(message);
}
@ -38,6 +42,8 @@ export class AnalyticsService {
this._requester.close();
}
public get ready() { return this._ready; }
private async _initConnection() {
this._requester = zmq.socket('pair');
@ -55,6 +61,8 @@ export class AnalyticsService {
this._requester.on("message", this._onAnalyticsMessage.bind(this));
this._ready = true;
}
private async _connectToAnalytics() {

Loading…
Cancel
Save