add additional shutdown logging
This commit is contained in:
parent
c79d66d48b
commit
4e609478f8
5 changed files with 20 additions and 0 deletions
|
|
@ -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<void> {
|
||||
// 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<void> {
|
||||
|
|
|
|||
|
|
@ -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<void> {
|
||||
// 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<void> {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ export class ChartManagementService implements OnApplicationShutdown {
|
|||
public async dispose(): Promise<void> {
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -612,6 +612,8 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
|||
|
||||
@bindThis
|
||||
public async onApplicationShutdown(signal?: string | undefined): Promise<void> {
|
||||
this.logger.info('Stopping BullMQ workers...');
|
||||
await this.stop();
|
||||
this.logger.info('Workers disposed.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,8 +309,13 @@ export class ServerService implements OnApplicationShutdown {
|
|||
|
||||
@bindThis
|
||||
public async dispose(): Promise<void> {
|
||||
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.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue