diff --git a/packages/backend/src/GlobalModule.ts b/packages/backend/src/GlobalModule.ts index 90dbdaf2a6..988da44512 100644 --- a/packages/backend/src/GlobalModule.ts +++ b/packages/backend/src/GlobalModule.ts @@ -14,6 +14,7 @@ import { createPostgresDataSource } from './postgres.js'; import { RepositoryModule } from './models/RepositoryModule.js'; import { allSettled } from './misc/promise-tracker.js'; import { GlobalEvents } from './core/GlobalEventService.js'; +import Logger from './logger.js'; import type { Provider, OnApplicationShutdown } from '@nestjs/common'; const $config: Provider = { @@ -164,6 +165,8 @@ const $meta: Provider = { exports: [$config, $db, $meta, $meilisearch, $redis, $redisForPub, $redisForSub, $redisForTimelines, $redisForReactions, $redisForRateLimit, RepositoryModule], }) export class GlobalModule implements OnApplicationShutdown { + private readonly logger = new Logger('global'); + constructor( @Inject(DI.db) private db: DataSource, @Inject(DI.redis) private redisClient: Redis.Redis, @@ -176,8 +179,10 @@ export class GlobalModule implements OnApplicationShutdown { public async dispose(): Promise { // Wait for all potential DB queries + this.logger.info('Finalizing active promises...'); await allSettled(); // And then disconnect from DB + this.logger.info('Disconnected from data sources...'); await this.db.destroy(); this.redisClient.disconnect(); this.redisForPub.disconnect(); @@ -185,6 +190,7 @@ export class GlobalModule implements OnApplicationShutdown { this.redisForTimelines.disconnect(); this.redisForReactions.disconnect(); this.redisForRateLimit.disconnect(); + this.logger.info('Global module disposed.'); } async onApplicationShutdown(signal: string): Promise { diff --git a/packages/backend/src/core/QueueModule.ts b/packages/backend/src/core/QueueModule.ts index 6dd48927c1..a48ffaab43 100644 --- a/packages/backend/src/core/QueueModule.ts +++ b/packages/backend/src/core/QueueModule.ts @@ -9,6 +9,7 @@ import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { baseQueueOptions, QUEUE } from '@/queue/const.js'; import { allSettled } from '@/misc/promise-tracker.js'; +import Logger from '@/logger.js'; import { DeliverJobData, EndedPollNotificationJobData, @@ -120,6 +121,8 @@ const $scheduleNotePost: Provider = { ], }) export class QueueModule implements OnApplicationShutdown { + private readonly logger = new Logger('queue'); + constructor( @Inject('queue:system') public systemQueue: SystemQueue, @Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue, @@ -135,8 +138,10 @@ export class QueueModule implements OnApplicationShutdown { public async dispose(): Promise { // Wait for all potential queue jobs + this.logger.info('Finalizing active promises...'); await allSettled(); // And then close all queues + this.logger.info('Closing BullMQ queues...'); await Promise.all([ this.systemQueue.close(), this.endedPollNotificationQueue.close(), @@ -149,6 +154,7 @@ export class QueueModule implements OnApplicationShutdown { this.systemWebhookDeliverQueue.close(), this.scheduleNotePostQueue.close(), ]); + this.logger.info('Queue module disposed.'); } async onApplicationShutdown(signal: string): Promise { diff --git a/packages/backend/src/core/chart/ChartManagementService.ts b/packages/backend/src/core/chart/ChartManagementService.ts index 81495c8a6c..4f151ff73d 100644 --- a/packages/backend/src/core/chart/ChartManagementService.ts +++ b/packages/backend/src/core/chart/ChartManagementService.ts @@ -75,6 +75,7 @@ export class ChartManagementService implements OnApplicationShutdown { public async dispose(): Promise { clearInterval(this.saveIntervalId); if (process.env.NODE_ENV !== 'test') { + this.logger.info('Saving charts for shutdown...'); for (const chart of this.charts) { await chart.save(); } diff --git a/packages/backend/src/queue/QueueProcessorService.ts b/packages/backend/src/queue/QueueProcessorService.ts index 4c1a6a1d9e..76a617f027 100644 --- a/packages/backend/src/queue/QueueProcessorService.ts +++ b/packages/backend/src/queue/QueueProcessorService.ts @@ -612,6 +612,8 @@ export class QueueProcessorService implements OnApplicationShutdown { @bindThis public async onApplicationShutdown(signal?: string | undefined): Promise { + this.logger.info('Stopping BullMQ workers...'); await this.stop(); + this.logger.info('Workers disposed.'); } } diff --git a/packages/backend/src/server/ServerService.ts b/packages/backend/src/server/ServerService.ts index 77b4519570..caa82d1ce8 100644 --- a/packages/backend/src/server/ServerService.ts +++ b/packages/backend/src/server/ServerService.ts @@ -309,8 +309,13 @@ export class ServerService implements OnApplicationShutdown { @bindThis public async dispose(): Promise { + this.logger.info('Disconnecting WebSocket clients...'); await this.streamingApiServerService.detach(); + + this.logger.info('Disconnecting HTTP clients....;'); await this.#fastify.close(); + + this.logger.info('Server disposed.'); } /**