update service status

This commit is contained in:
2024-10-23 15:43:50 +07:00
parent 7e55f4093b
commit 2872ac69ef
14 changed files with 212 additions and 32 deletions

View File

@@ -36,7 +36,24 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
this.logger.log('Try to connect database...');
await this.$connect();
for (let attempt = 1; attempt <= 3; attempt++) {
try {
await this.$connect();
break; // Exit loop if connection is successful
} catch (error) {
if (attempt < 3) {
this.logger.warn(
`Connection attempt ${attempt} failed. Retrying in 5000ms...`,
);
await new Promise((resolve) => setTimeout(resolve, 5000));
} else {
this.logger.error(
'Failed to connect to the database after 3 attempts.',
);
throw error; // Rethrow the error after 3 failed attempts
}
}
}
this.logger.log('Connected.');
}