Skip to content

Commit

Permalink
feat(status): Add startup status info
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Mar 24, 2020
1 parent 34ce803 commit 63e3990
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/framework/services/RabbitMq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class RabbitMqService extends IMService {
private qNameStartup: string;
private channelStartup: Channel;
private startTicket: MQMessage;
private waitingForTicket: boolean;

private qName: string;
private channel: Channel;
Expand Down Expand Up @@ -135,6 +136,8 @@ export class RabbitMqService extends IMService {

this.channelStartup = await this.conn.createChannel();
this.channelStartup.on('close', async (err) => {
this.waitingForTicket = false;

// If we have a ticket we are probably closing the channel after startup is complete
if (this.startTicket) {
return;
Expand All @@ -154,6 +157,7 @@ export class RabbitMqService extends IMService {

// Reset the ticket
this.startTicket = null;
this.waitingForTicket = true;

// Return a promise that resolves when we aquire a start ticket (a rabbitmq message)
return new Promise((resolve) => {
Expand All @@ -163,6 +167,8 @@ export class RabbitMqService extends IMService {
(msg) => {
console.log(`\x1b[32mAquired start ticket!\x1b[0m`);

this.waitingForTicket = false;

// Save the ticket so we can return it to the queue when our startup is done
this.startTicket = msg;
resolve();
Expand Down Expand Up @@ -228,6 +234,8 @@ export class RabbitMqService extends IMService {
connected: this.client.gatewayConnected,
guilds: this.client.guilds.size,
error: err ? err.message : null,
starting: !!this.startTicket,
waitingToStart: this.waitingForTicket,
tracking: {
pendingGuilds: this.client.tracking.pendingGuilds.size,
initialPendingGuilds: this.client.tracking.initialPendingGuilds
Expand Down

0 comments on commit 63e3990

Please sign in to comment.