Skip to content

Commit

Permalink
fix(stats): Correctly detect account state for Gmail/MS Graph API acc…
Browse files Browse the repository at this point in the history
…ounts
  • Loading branch information
andris9 committed Nov 1, 2024
1 parent 8bdc59c commit a5af1de
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/email-client/base-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class BaseClient {
return `${REDIS_PREFIX}iaz:logged`;
}

currentState() {
async currentState() {
return 'connected';
}

Expand Down
4 changes: 4 additions & 0 deletions lib/email-client/gmail-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ class GmailClient extends BaseClient {
return null;
}

async currentState() {
return (await this.redis.hget(this.getAccountKey(), 'state')) || 'disconnected';
}

async delete() {
clearTimeout(this.renewWatchTimer);
this.closed = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/email-client/imap-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ class IMAPClient extends BaseClient {
return this.imapClient && this.imapClient.usable && !this.isClosing && !this.isClosed;
}

currentState() {
async currentState() {
if (this.state === 'connected' && !this.isConnected()) {
this.state = 'disconnected';
}
Expand Down
4 changes: 4 additions & 0 deletions lib/email-client/outlook-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class OutlookClient extends BaseClient {
return null;
}

async currentState() {
return (await this.redis.hget(this.getAccountKey(), 'state')) || 'disconnected';
}

async delete() {
clearTimeout(this.renewWatchTimer);
this.closed = true;
Expand Down
18 changes: 7 additions & 11 deletions workers/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,24 +749,20 @@ class ConnectionHandler {
case 'countConnections': {
let results = Object.assign({}, DEFAULT_STATES);

let count = status => {
if (!results[status]) {
results[status] = 0;
}
results[status] += 1;
};

this.accounts.forEach(accountObject => {
for (let accountObject of this.accounts) {
let state;

if (!accountObject || !accountObject.connection) {
state = 'unassigned';
} else {
state = accountObject.connection.currentState();
state = await accountObject.connection.currentState();
}

return count(state);
});
if (!results[state]) {
results[state] = 0;
}
results[state] += 1;
}

return results;
}
Expand Down

0 comments on commit a5af1de

Please sign in to comment.