update order and fix approve center
This commit is contained in:
@@ -41,25 +41,32 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||
async onModuleInit() {
|
||||
this.logger.log('Try to connect database...');
|
||||
|
||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||
const maxRetry = parseInt(process.env.PRISMA_MAX_RETRY as string) ?? 3;
|
||||
const retryDelay = 10000;
|
||||
|
||||
for (let attempt = 1; attempt <= maxRetry; attempt++) {
|
||||
try {
|
||||
await this.$connect();
|
||||
break; // Exit loop if connection is successful
|
||||
this.logger.log('Connected.');
|
||||
return;
|
||||
} catch (error) {
|
||||
if (attempt < (parseInt(process.env.PRISMA_MAX_RETRY as string) ?? 3)) {
|
||||
if (attempt < maxRetry) {
|
||||
this.logger.warn(
|
||||
`Connection attempt ${attempt} failed. Retrying in 10000ms...`,
|
||||
`Connection attempt ${attempt} failed. Retrying in ${retryDelay}ms...`,
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 10000));
|
||||
await this.delay(retryDelay);
|
||||
} else {
|
||||
this.logger.error(
|
||||
'Failed to connect to the database after 3 attempts.',
|
||||
`Failed to connect to the database after ${maxRetry} attempts.`,
|
||||
);
|
||||
throw error; // Rethrow the error after 3 failed attempts
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.logger.log('Connected.');
|
||||
}
|
||||
|
||||
private delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async enableShutdownHooks(app: INestApplication) {
|
||||
|
||||
Reference in New Issue
Block a user