Fix bug in API logger (used setInterval instead of setTimeout).
This commit is contained in:
parent
2380bf8d1e
commit
0ce1581a87
@ -22,7 +22,7 @@ export class ApiLogAppender implements LogAppender {
|
|||||||
private lastSent = 0;
|
private lastSent = 0;
|
||||||
|
|
||||||
constructor(public readonly apiEndpoint: string, public authToken?: string, threshold?: LogLevel) {
|
constructor(public readonly apiEndpoint: string, public authToken?: string, threshold?: LogLevel) {
|
||||||
setInterval(this.checkPost, 1000);
|
setTimeout(this.checkPost, 1000);
|
||||||
if (threshold) { this.threshold = threshold; }
|
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() {
|
private doPost() {
|
||||||
if (this.msgBuffer.length > 0 && this.authToken) {
|
if (this.msgBuffer.length > 0 && this.authToken) {
|
||||||
|
|
||||||
@ -63,6 +51,19 @@ export class ApiLogAppender implements LogAppender {
|
|||||||
this.msgBuffer = [];
|
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;
|
export default ApiLogAppender;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user