Hi,
We are currently utilizing NestJS in combination with TypeORM and Postgres. However, we're encountering an issue wherein our application freezes when multiple calls are made to the controller using the service method below. Am I missing something on the way how transaction works ?
async processBatches(createUpdateBatchesDTO: any, response: any) {
const startTime = performance.now();
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
try {
await queryRunner.startTransaction();
for (const batch of createUpdateBatchesDTO?.data) {
await this.handleBatch(batch, queryRunner);
}
await queryRunner.commitTransaction();
response.status(HttpStatus.OK).send({ message: `Batch processing completed for ${createUpdateBatchesDTO?.data?.length} batch(es).` });
} catch (error) {
response.status(HttpStatus.INTERNAL_SERVER_ERROR).send({ message: `Error during batch processing`, error });
await queryRunner.rollbackTransaction();
} finally {
const releaseStartTime = performance.now();
await queryRunner.release();
const releaseFinishTime = performance.now();
this.logger.debug(
`Total processing time for releasing ${createUpdateBatchesDTO.data?.length} batches: ${releaseFinishTime - releaseStartTime} ms.`
);
const finishTime = performance.now();
this.logger.debug(
`Total processing time for queries of ${createUpdateBatchesDTO.data?.length} batches: ${finishTime - startTime} ms.`
);
}
}