diff --git a/src/infrastructure/database/prisma.service.ts b/src/infrastructure/database/prisma.service.ts index 7ffd32d..1f22e27 100644 --- a/src/infrastructure/database/prisma.service.ts +++ b/src/infrastructure/database/prisma.service.ts @@ -1,4 +1,4 @@ -import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; +import { Injectable, OnModuleInit, OnModuleDestroy, Logger } from '@nestjs/common'; import { PrismaClient } from '@prisma/client'; @Injectable() @@ -6,8 +6,15 @@ export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { + private readonly logger = new Logger(PrismaService.name); + async onModuleInit() { - await this.$connect(); + try { + await this.$connect(); + this.logger.log('Database connected'); + } catch (err: any) { + this.logger.error(`Database connection failed: ${err.message}`); + } } async onModuleDestroy() { diff --git a/src/modules/admin-costs/cost-aggregation.service.ts b/src/modules/admin-costs/cost-aggregation.service.ts index 0ce7428..7e1fa19 100644 --- a/src/modules/admin-costs/cost-aggregation.service.ts +++ b/src/modules/admin-costs/cost-aggregation.service.ts @@ -11,7 +11,11 @@ export class CostAggregationService implements OnModuleInit, OnModuleDestroy { constructor(private readonly prisma: PrismaService) {} async onModuleInit() { - await this.aggregateToday(); + try { + await this.aggregateToday(); + } catch (err: any) { + this.logger.warn(`Initial cost aggregation failed: ${err.message}`); + } this.timer = setInterval(() => this.aggregateToday(), AGGREGATE_INTERVAL_MS); } diff --git a/src/modules/admin-metrics/metrics-cleanup.service.ts b/src/modules/admin-metrics/metrics-cleanup.service.ts index 7d7a93c..347c98d 100644 --- a/src/modules/admin-metrics/metrics-cleanup.service.ts +++ b/src/modules/admin-metrics/metrics-cleanup.service.ts @@ -12,8 +12,8 @@ export class MetricsCleanupService implements OnModuleInit, OnModuleDestroy { constructor(private readonly prisma: PrismaService) {} async onModuleInit() { - await this.cleanup(); - this.timer = setInterval(() => this.cleanup(), CLEANUP_INTERVAL_MS); + await this.cleanup().catch(() => {}); + this.timer = setInterval(() => this.cleanup().catch(() => {}), CLEANUP_INTERVAL_MS); } onModuleDestroy() {