diff --git a/web/src/services/logging/api-log-appender.ts b/web/src/services/logging/api-log-appender.ts index 3979e09..a0579e3 100644 --- a/web/src/services/logging/api-log-appender.ts +++ b/web/src/services/logging/api-log-appender.ts @@ -22,7 +22,7 @@ export class ApiLogAppender implements LogAppender { private lastSent = 0; constructor(public readonly apiEndpoint: string, public authToken?: string, threshold?: LogLevel) { - setInterval(this.checkPost, 1000); + setTimeout(this.checkPost, 1000); if (threshold) { this.threshold = threshold; } } @@ -38,18 +38,6 @@ export class ApiLogAppender implements LogAppender { }); } - private checkPost = () => { - const now = Date.now(); - const min = this.lastSent + (this.minimumTimePassedInSec * 1000); - const max = this.lastSent + (this.maximumTimePassedInSec * 1000); - - if ( (this.msgBuffer.length >= this.batchSize && min < now) || - (this.msgBuffer.length > 0 && max < now) ) { - this.doPost(); - } - setInterval(this.checkPost, Math.max(10000, this.minimumTimePassedInSec * 1000)); - } - private doPost() { if (this.msgBuffer.length > 0 && this.authToken) { @@ -63,6 +51,19 @@ export class ApiLogAppender implements LogAppender { this.msgBuffer = []; } } + + private checkPost = () => { + const now = Date.now(); + const min = this.lastSent + (this.minimumTimePassedInSec * 1000); + const max = this.lastSent + (this.maximumTimePassedInSec * 1000); + + if ( (this.msgBuffer.length >= this.batchSize && min < now) || + (this.msgBuffer.length > 0 && max < now) ) { + this.doPost(); + } + setTimeout(this.checkPost, Math.max(10000, this.minimumTimePassedInSec * 1000)); + } + } export default ApiLogAppender;