Skip to content

Commit

Permalink
Merge pull request #837 from Sanofi-IADC/feature/WEB-2246
Browse files Browse the repository at this point in the history
fix: WEB-2246 added pool size option mongoose to handle memory
  • Loading branch information
sairam459 committed Jun 3, 2024
2 parents ea855a6 + 8681c66 commit 013017c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MONGOOSE_HOST = mongo1
MONGOOSE_PORT = 27017
MONGOOSE_USERNAME
MONGOOSE_PASSWORD
MONGOOSE_POOL_SIZE = 10

REDIS_HOST = redis
REDIS_PORT = 6379
Expand Down
1 change: 1 addition & 0 deletions example.rep.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MONGOOSE_HOST_READ = mongo2
MONGOOSE_PORT_READ = 27017
MONGOOSE_USERNAME
MONGOOSE_PASSWORD
MONGOOSE_POOL_SIZE = 10

REDIS_HOST = redis
REDIS_PORT = 6379
Expand Down
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { TagModule } from './tag/tag.module';
import { HealthController } from './health/health.controller';
import { AuthModule } from './auth/auth.module';
import { GqlContext } from './auth/gql-context';
import { DatabaseService } from './common/DatabaseService';

@Module({
imports: [
Expand Down Expand Up @@ -91,7 +92,7 @@ import { GqlContext } from './auth/gql-context';
WebhookModule,
AuthModule,
],
providers: [AppService],
providers: [AppService, DatabaseService],
controllers: [AppController, HealthController],
})
export class AppModule {}
13 changes: 13 additions & 0 deletions src/common/DatabaseService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Injectable, OnModuleDestroy } from '@nestjs/common';
import { InjectConnection } from '@nestjs/mongoose';
import { Connection } from 'mongoose';

@Injectable()
export class DatabaseService implements OnModuleDestroy {
constructor(@InjectConnection() private readonly connection: Connection) {}

async onModuleDestroy() {
await this.connection.close();
console.log('Mongoose connection closed');

Check warning on line 11 in src/common/DatabaseService.ts

View workflow job for this annotation

GitHub Actions / Quality

Unexpected console statement
}
}
6 changes: 6 additions & 0 deletions src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export class ConfigService {
readPreference: this.get('REPLICASET') !== undefined ? readPreference : null,
user: this.get('MONGOOSE_USERNAME'),
pass: this.get('MONGOOSE_PASSWORD'),
maxPoolSize: this.get('MONGOOSE_POOL_SIZE') || 20,
retryAttempts: 2,
connectTimeoutMS: 60000,
useUnifiedTopology: true,
useNewUrlParser: true,
socketTimeoutMS: 60000,
};
if (this.get('SSL_VALIDATE') === true) {
options = {
Expand Down

0 comments on commit 013017c

Please sign in to comment.