issue # graceful shutdown 구현 중
All checks were successful
Test CI / build (push) Successful in 3m22s
All checks were successful
Test CI / build (push) Successful in 3m22s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Global, Module } from "@nestjs/common";
|
||||
import { Global, Inject, Module, OnApplicationShutdown } from "@nestjs/common";
|
||||
import { Pool } from "pg";
|
||||
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||
@@ -9,16 +9,28 @@ import * as schema from '../../drizzle/schema';
|
||||
imports: [ConfigModule],
|
||||
providers: [
|
||||
{
|
||||
provide: "DRIZZLE",
|
||||
useFactory: (configService: ConfigService): NodePgDatabase<typeof schema> => {
|
||||
const pool = new Pool({
|
||||
provide: "DB_POOL",
|
||||
useFactory: (configService: ConfigService) => {
|
||||
return new Pool({
|
||||
connectionString: configService.get<string>('PG_DATABASE_URL')
|
||||
});
|
||||
return drizzle(pool, { schema: schema });
|
||||
},
|
||||
inject: [ConfigService]
|
||||
},
|
||||
{
|
||||
provide: "DRIZZLE",
|
||||
useFactory: (pool: Pool): NodePgDatabase<typeof schema> => {
|
||||
return drizzle(pool, { schema: schema });
|
||||
},
|
||||
inject: ["DB_POOL"]
|
||||
}
|
||||
],
|
||||
exports: ["DRIZZLE"]
|
||||
})
|
||||
export class DbModule {}
|
||||
export class DbModule implements OnApplicationShutdown {
|
||||
constructor(@Inject('DB_POOL') private readonly pool: Pool) {}
|
||||
|
||||
async onApplicationShutdown(signal?: string) {
|
||||
await this.pool.end();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@ async function bootstrap() {
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
app.enableShutdownHooks();
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Global, Module } from "@nestjs/common";
|
||||
import { Global, Inject, Module, OnApplicationShutdown } from "@nestjs/common";
|
||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||
import Redis from "ioredis";
|
||||
|
||||
@@ -18,4 +18,10 @@ import Redis from "ioredis";
|
||||
],
|
||||
exports: ["REDIS"]
|
||||
})
|
||||
export class RedisModule{}
|
||||
export class RedisModule implements OnApplicationShutdown {
|
||||
constructor(@Inject("REDIS") private readonly redis: Redis) {}
|
||||
|
||||
async onApplicationShutdown(signal?: string) {
|
||||
await this.redis.quit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user