Skip to content

Commit

Permalink
fix(startup): Fix returning ticket causing restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Mar 24, 2020
1 parent 17812bb commit 1c61f26
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/framework/services/RabbitMq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ export class RabbitMqService extends IMService {

this.channelStartup = await this.conn.createChannel();
this.channelStartup.on('close', async (err) => {
// If we have a ticket we are probably closing the channel after startup is complete
if (this.startTicket) {
return;
}

if (err) {
captureException(err);
console.error(err);
Expand All @@ -147,13 +152,16 @@ export class RabbitMqService extends IMService {
await this.channelStartup.prefetch(1);
await this.channelStartup.assertQueue(this.qNameStartup, { durable: true, autoDelete: false });

// Reset the ticket
this.startTicket = null;

// Return a promise that resolves when we aquire a start ticket (a rabbitmq message)
return new Promise((resolve) => {
// Start listening on the queue for one message (our start ticket)
this.channelStartup.consume(
this.qNameStartup,
(msg) => {
console.log('Aquired start ticket...');
console.log(`Aquired start ticket...`);

// Save the ticket so we can return it to the queue when our startup is done
this.startTicket = msg;
Expand Down

0 comments on commit 1c61f26

Please sign in to comment.