This commit is contained in:
syuilo 2023-05-29 13:21:26 +09:00
parent fd7b77c542
commit b6f21b6edb
16 changed files with 104 additions and 21 deletions

View file

@ -100,7 +100,7 @@ export class GlobalModule implements OnApplicationShutdown {
@Inject(DI.redisForSub) private redisForSub: Redis.Redis,
) {}
async onApplicationShutdown(signal: string): Promise<void> {
public async dispose(): Promise<void> {
if (process.env.NODE_ENV === 'test') {
// XXX:
// Shutting down the existing connections causes errors on Jest as
@ -116,4 +116,8 @@ export class GlobalModule implements OnApplicationShutdown {
this.redisForSub.disconnect(),
]);
}
async onApplicationShutdown(signal: string): Promise<void> {
await this.dispose();
}
}

View file

@ -55,11 +55,6 @@ export class AntennaService implements OnApplicationShutdown {
this.redisForSub.on('message', this.onRedisMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
this.redisForSub.off('message', this.onRedisMessage);
}
@bindThis
private async onRedisMessage(_: string, data: string): Promise<void> {
const obj = JSON.parse(data);
@ -196,4 +191,14 @@ export class AntennaService implements OnApplicationShutdown {
return this.antennas;
}
@bindThis
public dispose(): void {
this.redisForSub.off('message', this.onRedisMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -166,7 +166,12 @@ export class CacheService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
this.redisForSub.off('message', this.onMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -120,8 +120,13 @@ export class MetaService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
clearInterval(this.intervalId);
this.redisForSub.off('message', this.onMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -790,7 +790,13 @@ export class NoteCreateService implements OnApplicationShutdown {
return mentionedUsers;
}
onApplicationShutdown(signal?: string | undefined) {
@bindThis
public dispose(): void {
this.#shutdownController.abort();
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -122,7 +122,13 @@ export class NoteReadService implements OnApplicationShutdown {
}
}
onApplicationShutdown(signal?: string | undefined): void {
@bindThis
public dispose(): void {
this.#shutdownController.abort();
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -152,7 +152,13 @@ export class NotificationService implements OnApplicationShutdown {
*/
}
onApplicationShutdown(signal?: string | undefined): void {
@bindThis
public dispose(): void {
this.#shutdownController.abort();
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -100,7 +100,7 @@ export class QueueModule implements OnApplicationShutdown {
@Inject('queue:webhookDeliver') public webhookDeliverQueue: WebhookDeliverQueue,
) {}
async onApplicationShutdown(signal: string): Promise<void> {
public async dispose(): Promise<void> {
if (process.env.NODE_ENV === 'test') {
// XXX:
// Shutting down the existing connections causes errors on Jest as
@ -120,4 +120,8 @@ export class QueueModule implements OnApplicationShutdown {
this.webhookDeliverQueue.close(),
]);
}
async onApplicationShutdown(signal: string): Promise<void> {
await this.dispose();
}
}

View file

@ -433,7 +433,12 @@ export class RoleService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
this.redisForSub.off('message', this.onMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -81,7 +81,12 @@ export class WebhookService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
this.redisForSub.off('message', this.onMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -60,7 +60,8 @@ export class ChartManagementService implements OnApplicationShutdown {
}, 1000 * 60 * 20);
}
async onApplicationShutdown(signal: string): Promise<void> {
@bindThis
public async dispose(): Promise<void> {
clearInterval(this.saveIntervalId);
if (process.env.NODE_ENV !== 'test') {
await Promise.all(
@ -68,4 +69,9 @@ export class ChartManagementService implements OnApplicationShutdown {
);
}
}
@bindThis
async onApplicationShutdown(signal: string): Promise<void> {
await this.dispose();
}
}

View file

@ -34,7 +34,12 @@ export class JanitorService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
clearInterval(this.intervalId);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -83,7 +83,12 @@ export class QueueStatsService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
clearInterval(this.intervalId);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}

View file

@ -63,9 +63,14 @@ export class ServerStatsService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
clearInterval(this.intervalId);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}
// CPU STAT

View file

@ -222,7 +222,13 @@ export class ServerService implements OnApplicationShutdown {
await fastify.ready();
}
async onApplicationShutdown(signal: string): Promise<void> {
@bindThis
public async dispose(): Promise<void> {
await this.#fastify.close();
}
@bindThis
async onApplicationShutdown(signal: string): Promise<void> {
await this.dispose();
}
}

View file

@ -359,7 +359,12 @@ export class ApiCallService implements OnApplicationShutdown {
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
public dispose(): void {
clearInterval(this.userIpHistoriesClearIntervalId);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
}
}