Browse Source

Minor server fixes (#438)

* Disable webhook: TypeError: Cannot read property 'toString' of undefined #415
* UnhandledPromiseRejectionWarning #419
pull/1/head
rozetko 6 years ago committed by GitHub
parent
commit
7d4d30938a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      server/src/controllers/analytics_controller.ts
  2. 2
      server/src/services/analytics_service.ts
  3. 5
      server/src/services/data_puller.ts

21
server/src/controllers/analytics_controller.ts

@ -99,6 +99,9 @@ export function terminate() {
async function runTask(task: AnalyticsTask): Promise<TaskResult> { async function runTask(task: AnalyticsTask): Promise<TaskResult> {
return new Promise<TaskResult>((resolver: TaskResolver) => { return new Promise<TaskResult>((resolver: TaskResolver) => {
if(!analyticsService.ready) {
throw new Error(`Can't send task, analytics is not ready`);
}
taskResolvers.set(task.id, resolver); // it will be resolved in onTaskResult() taskResolvers.set(task.id, resolver); // it will be resolved in onTaskResult()
analyticsService.sendTask(task); // we dont wait for result here analyticsService.sendTask(task); // we dont wait for result here
}); });
@ -291,15 +294,23 @@ export async function runDetect(id: AnalyticUnit.AnalyticUnitId) {
} }
} }
export async function remove(id: AnalyticUnit.AnalyticUnitId) { export async function remove(analyticUnitId: AnalyticUnit.AnalyticUnitId) {
let task = new AnalyticsTask(id, AnalyticsTaskType.CANCEL); await cancelAnalyticsTask(analyticUnitId);
await runTask(task);
if(dataPuller !== undefined) { if(dataPuller !== undefined) {
dataPuller.deleteUnit(id); dataPuller.deleteUnit(analyticUnitId);
} }
await AnalyticUnit.remove(id); await AnalyticUnit.remove(analyticUnitId);
}
async function cancelAnalyticsTask(analyticUnitId: AnalyticUnit.AnalyticUnitId) {
try {
let task = new AnalyticsTask(analyticUnitId, AnalyticsTaskType.CANCEL);
await runTask(task);
} catch(e) {
console.log(`Can't cancel analytics task for "${analyticUnitId}": ${e.message}`);
}
} }
export async function deleteNonDetectedSegments(id, payload) { export async function deleteNonDetectedSegments(id, payload) {

2
server/src/services/analytics_service.ts

@ -32,7 +32,7 @@ export class AnalyticsService {
public async sendTask(task: AnalyticsTask): Promise<void> { public async sendTask(task: AnalyticsTask): Promise<void> {
if(!this._ready) { if(!this._ready) {
return Promise.reject("Analytics is not ready"); throw new Error('Analytics is not ready');
} }
let method = task.type === AnalyticsTaskType.PUSH ? let method = task.type === AnalyticsTaskType.PUSH ?
AnalyticsMessageMethod.DATA : AnalyticsMessageMethod.TASK AnalyticsMessageMethod.DATA : AnalyticsMessageMethod.TASK

5
server/src/services/data_puller.ts

@ -165,7 +165,10 @@ export class DataPuller {
} }
try { try {
const time = this._unitTimes[analyticUnit.id] const time = this._unitTimes[analyticUnit.id];
if(time === undefined) {
throw new Error(`Analytic unit ${analyticUnit.id} is deleted from puller`);
}
const now = Date.now(); const now = Date.now();
const res = await this.pullData(analyticUnit, time, now); const res = await this.pullData(analyticUnit, time, now);
this._grafanaAvailableConsoleReporter(true); this._grafanaAvailableConsoleReporter(true);

Loading…
Cancel
Save