Skip to content

Commit 5b806d8

Browse files
authored
Merge pull request #162 from hypersign-protocol/fix-race-mongo
Fix race mongo
2 parents 6b8efc2 + bae512a commit 5b806d8

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@nestjs/config": "^2.2.0",
3232
"@nestjs/core": "^9.0.0",
3333
"@nestjs/jwt": "^10.0.1",
34+
"node-cache": "^5.1.2",
3435
"@nestjs/mongoose": "^9.2.1",
3536
"@nestjs/passport": "^9.0.0",
3637
"@nestjs/platform-express": "^9.0.0",

src/tx-send-module/tx-send-module.service.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,32 @@ export class TxSendModuleService {
118118
}
119119

120120
async connect() {
121-
Logger.log('Connecting Rabbit');
122-
const connection = await amqp.connect(
123-
this.configService.get('RABBIT_MQ_URI'),
124-
);
125-
this.channel = await connection.createChannel();
126-
const { address: granterAddress } =
127-
await this.hidWalletService.generateWallet(
128-
this.configService.get('MNEMONIC'),
121+
try {
122+
Logger.log('Connecting Rabbit');
123+
const connection = await amqp.connect(
124+
this.configService.get('RABBIT_MQ_URI'),
129125
);
130-
this.granterAddress = granterAddress;
131-
Logger.log('Connected Rabbit');
126+
connection.on('error', (err) => {
127+
console.error('Connection error:', err);
128+
});
129+
130+
connection.on('close', () => {
131+
Logger.error('Connection closed, reconnecting...', 'RabbitMQ');
132+
});
133+
this.channel = await connection.createChannel();
134+
this.channel.on('error', (err) => {
135+
Logger.error(err, 'RabbitMQ');
136+
});
137+
138+
const { address: granterAddress } =
139+
await this.hidWalletService.generateWallet(
140+
this.configService.get('MNEMONIC'),
141+
);
142+
this.granterAddress = granterAddress;
143+
Logger.log('Connected Rabbit');
144+
} catch (error) {
145+
Logger.error(error, 'RabbitMQ');
146+
}
132147
}
133148

134149
async prepareRegisterCredentialStatus(

0 commit comments

Comments
 (0)