mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01: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) {
 | 
			
		||||
        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) {
 | 
			
		||||
@ -260,12 +266,18 @@ export default class ClientMetricsServiceV2 {
 | 
			
		||||
 | 
			
		||||
    async bulkAdd(): Promise<void> {
 | 
			
		||||
        if (this.unsavedMetrics.length > 0) {
 | 
			
		||||
            // Make a copy of `unsavedMetrics` in case new metrics
 | 
			
		||||
            // arrive while awaiting `batchInsertMetrics`.
 | 
			
		||||
            const copy = [...this.unsavedMetrics];
 | 
			
		||||
            this.unsavedMetrics = [];
 | 
			
		||||
            await this.clientMetricsStoreV2.batchInsertMetrics(copy);
 | 
			
		||||
            this.config.eventBus.emit(CLIENT_METRICS_ADDED, copy);
 | 
			
		||||
            try {
 | 
			
		||||
                // Make a copy of `unsavedMetrics` in case new metrics
 | 
			
		||||
                // arrive while awaiting `batchInsertMetrics`.
 | 
			
		||||
                const copy = [...this.unsavedMetrics];
 | 
			
		||||
                this.unsavedMetrics = [];
 | 
			
		||||
                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(
 | 
			
		||||
        () => clientMetricsServiceV2.bulkAdd().catch(console.error),
 | 
			
		||||
        () => clientMetricsServiceV2.bulkAdd(),
 | 
			
		||||
        secondsToMilliseconds(5),
 | 
			
		||||
        'bulkAddMetrics',
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    schedulerService.schedule(
 | 
			
		||||
        () => clientMetricsServiceV2.clearMetrics(48).catch(console.error),
 | 
			
		||||
        () => clientMetricsServiceV2.clearMetrics(48),
 | 
			
		||||
        hoursToMilliseconds(12),
 | 
			
		||||
        'clearMetrics',
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user