[client-sync] Refactor raw message IMAP connection pool use

Summary: In preparation for removing timeout handling from IMAPConnectionPool.

Test Plan: Run locally

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D4168
This commit is contained in:
Mark Hahnenberg 2017-03-09 14:32:43 -08:00
parent acd3bf5954
commit 19528ca78a

View file

@ -141,10 +141,8 @@ module.exports = (sequelize, Sequelize) => {
const folder = await this.getFolder(); const folder = await this.getFolder();
let numTimeoutErrors = 0; let numTimeoutErrors = 0;
let result = null; let result = null;
await IMAPConnectionPool.withConnectionsForAccount(account, {
desiredCount: 1, const onConnected = async ([connection]) => {
logger,
onConnected: async ([connection]) => {
const imapBox = await connection.openBox(folder.name); const imapBox = await connection.openBox(folder.name);
const message = await imapBox.fetchMessage(this.folderImapUID); const message = await imapBox.fetchMessage(this.folderImapUID);
if (!message) { if (!message) {
@ -155,8 +153,9 @@ module.exports = (sequelize, Sequelize) => {
// MUST be decoded before you can figure out how to interpret the // MUST be decoded before you can figure out how to interpret the
// body MIME bytes // body MIME bytes
result = `${message.headers}${message.parts.TEXT}`; result = `${message.headers}${message.parts.TEXT}`;
}, };
onTimeout: (socketTimeout) => {
const onTimeout = (socketTimeout) => {
numTimeoutErrors += 1; numTimeoutErrors += 1;
Actions.recordUserEvent('Timeout error downloading raw message', { Actions.recordUserEvent('Timeout error downloading raw message', {
accountId: account.id, accountId: account.id,
@ -164,8 +163,15 @@ module.exports = (sequelize, Sequelize) => {
socketTimeout, socketTimeout,
numTimeoutErrors, numTimeoutErrors,
}); });
}, };
await IMAPConnectionPool.withConnectionsForAccount(account, {
desiredCount: 1,
logger,
onConnected,
onTimeout,
}); });
return result; return result;
}, },