Fix retrun value in MoveToFolderIMAP task

This commit is contained in:
Evan Morikawa 2016-06-29 12:04:46 -07:00
parent 941180c1df
commit 7cf59c3c11
3 changed files with 16 additions and 2 deletions

View file

@ -250,11 +250,15 @@ class IMAPConnection extends EventEmitter {
}
runOperation(operation) {
console.log("Running operation")
console.log(operation.constructor.name)
if (!this._imap) {
throw new Error(`IMAPConnection::runOperation - You need to call connect() first.`)
}
return new Promise((resolve, reject) => {
this._queue.push({operation, resolve, reject});
console.log("Pushing onto queue")
console.log(this._currentOperation)
if (this._imap.state === 'authenticated' && !this._currentOperation) {
this.processNextOperation();
}
@ -262,9 +266,12 @@ class IMAPConnection extends EventEmitter {
}
processNextOperation() {
console.log("Process next operation")
console.log(this._currentOperation)
if (this._currentOperation) { return }
this._currentOperation = this._queue.shift();
if (!this._currentOperation) {
console.log("queue empty")
this.emit('queue-empty');
return
}
@ -272,6 +279,7 @@ class IMAPConnection extends EventEmitter {
const {operation, resolve, reject} = this._currentOperation;
console.log(`Starting task ${operation.description()}`)
const result = operation.run(this._db, this);
console.log(`have operation promise`)
if (result instanceof Promise === false) {
reject(new NylasError(`Expected ${operation.constructor.name} to return promise.`))
}

View file

@ -100,6 +100,7 @@ class SyncWorker {
}
ensureConnection() {
console.log("ENSURING CONNECTION")
if (this._conn) {
return this._conn.connect();
}
@ -128,6 +129,7 @@ class SyncWorker {
}
syncbackMessageActions() {
console.log("SYNCBACK MESSAGE ACTIONS")
const where = {where: {status: "NEW"}, limit: 100};
return this._db.SyncbackRequest.findAll(where)
.map((req) => SyncbackTaskFactory.create(this._account, req))
@ -151,6 +153,7 @@ class SyncWorker {
}
syncAllCategories() {
console.log("Syncing all categories")
const {Category} = this._db;
const {folderSyncOptions} = this._account.syncPolicy;
@ -167,14 +170,18 @@ class SyncWorker {
}
performSync() {
console.log("Performing sync")
return this._conn.runOperation(new FetchCategoryList(this._account.provider))
.then(() => this.syncbackMessageActions())
.then(() => this.syncAllCategories())
}
syncNow() {
console.log("SYNCING NOW")
clearTimeout(this._syncTimer);
console.log(process.env.SYNC_AFTER_ERRORS)
console.log(this._account.errored())
if (!process.env.SYNC_AFTER_ERRORS && this._account.errored()) {
console.log(`SyncWorker: Account ${this._account.emailAddress} is in error state - Skipping sync`)
return

View file

@ -8,7 +8,6 @@ class MoveToFolderIMAP extends SyncbackTask {
run(db, imap) {
console.log("------------------ RUNNING MOVE TO FOLDER IMAP")
console.log(this.syncbackRequestObject())
const threadId = this.syncbackRequestObject().props.threadId
const toFolderId = this.syncbackRequestObject().props.folderId
@ -17,7 +16,7 @@ class MoveToFolderIMAP extends SyncbackTask {
return imap.moveAsync(message.messageId, toFolderId)
}
TaskHelpers.forEachMessageInThread({threadId, db, imap, callback: eachMsg})
return TaskHelpers.forEachMessageInThread({threadId, db, imap, callback: eachMsg})
// for (const {message, category} of msgGenerator) {
// imap.moveAsync(messageId)