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