mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
chore: use logger instead of console.error (#10150)
This commit is contained in:
parent
02876a1c08
commit
0bad9101fc
@ -72,7 +72,13 @@ export default class ClientMetricsServiceV2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clearMetrics(hoursAgo: number) {
|
async clearMetrics(hoursAgo: number) {
|
||||||
return this.clientMetricsStoreV2.clearMetrics(hoursAgo);
|
try {
|
||||||
|
await this.clientMetricsStoreV2.clearMetrics(hoursAgo);
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.warn(
|
||||||
|
`Failed to clear client metrics older than ${hoursAgo} hours: ${e.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearDailyMetrics(daysAgo: number) {
|
async clearDailyMetrics(daysAgo: number) {
|
||||||
@ -260,12 +266,18 @@ export default class ClientMetricsServiceV2 {
|
|||||||
|
|
||||||
async bulkAdd(): Promise<void> {
|
async bulkAdd(): Promise<void> {
|
||||||
if (this.unsavedMetrics.length > 0) {
|
if (this.unsavedMetrics.length > 0) {
|
||||||
// Make a copy of `unsavedMetrics` in case new metrics
|
try {
|
||||||
// arrive while awaiting `batchInsertMetrics`.
|
// Make a copy of `unsavedMetrics` in case new metrics
|
||||||
const copy = [...this.unsavedMetrics];
|
// arrive while awaiting `batchInsertMetrics`.
|
||||||
this.unsavedMetrics = [];
|
const copy = [...this.unsavedMetrics];
|
||||||
await this.clientMetricsStoreV2.batchInsertMetrics(copy);
|
this.unsavedMetrics = [];
|
||||||
this.config.eventBus.emit(CLIENT_METRICS_ADDED, copy);
|
await this.clientMetricsStoreV2.batchInsertMetrics(copy);
|
||||||
|
this.config.eventBus.emit(CLIENT_METRICS_ADDED, copy);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(
|
||||||
|
`Failed to bulk add client metrics: ${error.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,13 +152,13 @@ export const scheduleServices = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
schedulerService.schedule(
|
schedulerService.schedule(
|
||||||
() => clientMetricsServiceV2.bulkAdd().catch(console.error),
|
() => clientMetricsServiceV2.bulkAdd(),
|
||||||
secondsToMilliseconds(5),
|
secondsToMilliseconds(5),
|
||||||
'bulkAddMetrics',
|
'bulkAddMetrics',
|
||||||
);
|
);
|
||||||
|
|
||||||
schedulerService.schedule(
|
schedulerService.schedule(
|
||||||
() => clientMetricsServiceV2.clearMetrics(48).catch(console.error),
|
() => clientMetricsServiceV2.clearMetrics(48),
|
||||||
hoursToMilliseconds(12),
|
hoursToMilliseconds(12),
|
||||||
'clearMetrics',
|
'clearMetrics',
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user