feat: add api liveness and readiness checks
This commit is contained in:
27
backend/libs/infrastructure/src/postgres/postgres.module.ts
Normal file
27
backend/libs/infrastructure/src/postgres/postgres.module.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Inject, Injectable, Module, OnModuleDestroy } from '@nestjs/common';
|
||||
import { Pool } from 'pg';
|
||||
import { APP_ENVIRONMENT, AppEnvironment } from '../../../configuration/src';
|
||||
|
||||
export const POSTGRES_POOL = Symbol('POSTGRES_POOL');
|
||||
|
||||
export const postgresPoolProvider = {
|
||||
provide: POSTGRES_POOL,
|
||||
inject: [APP_ENVIRONMENT],
|
||||
useFactory: (env: AppEnvironment) =>
|
||||
new Pool({ connectionString: env.databaseUrl }),
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
class PostgresLifecycle implements OnModuleDestroy {
|
||||
constructor(@Inject(POSTGRES_POOL) private readonly pool: Pool) {}
|
||||
|
||||
async onModuleDestroy(): Promise<void> {
|
||||
await this.pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Module({
|
||||
providers: [postgresPoolProvider, PostgresLifecycle],
|
||||
exports: [postgresPoolProvider],
|
||||
})
|
||||
export class PostgresModule {}
|
||||
Reference in New Issue
Block a user