From 36903e797ebd280319f543cacb2d9b871966bcd6 Mon Sep 17 00:00:00 2001 From: wangdl Date: Sat, 20 Jun 2026 16:25:16 +0800 Subject: [PATCH] fix: prevent hourly API crash from unhandled CostAggregationService rejection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - setInterval callback lacked .catch() — unhandled Promise rejection crashed the Node.js process exactly 1 hour after startup - AiUsageLog table missing in current DB → aggregateToday() rejects → process.exit(1) in Node 22 Co-Authored-By: Claude --- src/modules/admin-costs/cost-aggregation.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/admin-costs/cost-aggregation.service.ts b/src/modules/admin-costs/cost-aggregation.service.ts index 7e1fa19..b776609 100644 --- a/src/modules/admin-costs/cost-aggregation.service.ts +++ b/src/modules/admin-costs/cost-aggregation.service.ts @@ -16,7 +16,7 @@ export class CostAggregationService implements OnModuleInit, OnModuleDestroy { } catch (err: any) { this.logger.warn(`Initial cost aggregation failed: ${err.message}`); } - this.timer = setInterval(() => this.aggregateToday(), AGGREGATE_INTERVAL_MS); + this.timer = setInterval(() => this.aggregateToday().catch(err => this.logger.warn(`Hourly cost aggregation failed: ${err.message}`)), AGGREGATE_INTERVAL_MS); } onModuleDestroy() {