Clean up loggin

This commit is contained in:
Evan Morikawa 2016-06-29 12:07:51 -07:00
parent bdfee404e5
commit d26824771d
3 changed files with 2 additions and 27 deletions

View file

@ -257,15 +257,11 @@ 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();
}
@ -273,33 +269,29 @@ 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
}
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.`))
}
result
.then(() => {
this._currentOperation = null;
console.log(`Finished task ${operation.description()}`)
console.log(`Finished task: ${operation.description()}`)
resolve();
this.processNextOperation();
})
.catch((err) => {
this._currentOperation = null;
console.log(`Task errored: ${operation.description()}`)
console.error(err)
reject(err);
})
}

View file

@ -25,7 +25,6 @@ class SyncWorker {
this.syncNow();
this._onMessage = this._onMessage.bind(this);
console.log("SYNC WORKER -------------------")
this._listener = PubsubConnector.observe(account.id).subscribe(this._onMessage)
}
@ -41,10 +40,7 @@ class SyncWorker {
}
_onMessage(msg) {
console.log("============= ON MESSAGE")
console.log(msg)
const {type} = JSON.parse(msg);
console.log(type)
switch (type) {
case MessageTypes.ACCOUNT_UPDATED:
this._onAccountUpdated(); break;
@ -100,7 +96,6 @@ class SyncWorker {
}
ensureConnection() {
console.log("ENSURING CONNECTION")
if (this._conn) {
return this._conn.connect();
}
@ -129,7 +124,6 @@ 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))
@ -140,20 +134,15 @@ class SyncWorker {
const syncbackRequest = task.syncbackRequestObject()
return this._conn.runOperation(task)
.then(() => {
console.log(`Task succeeded: ${task.constructor.name}`)
syncbackRequest.status = "SUCCEEDED"
})
.catch((error) => {
console.log(`Task errored`)
console.error(error)
console.error(error.message)
syncbackRequest.error = error
syncbackRequest.status = "FAILED"
}).finally(() => syncbackRequest.save())
}
syncAllCategories() {
console.log("Syncing all categories")
const {Category} = this._db;
const {folderSyncOptions} = this._account.syncPolicy;
@ -170,18 +159,14 @@ 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

@ -7,12 +7,10 @@ class MoveToFolderIMAP extends SyncbackTask {
}
run(db, imap) {
console.log("------------------ RUNNING MOVE TO FOLDER IMAP")
const threadId = this.syncbackRequestObject().props.threadId
const toFolderId = this.syncbackRequestObject().props.folderId
const eachMsg = ({message}) => {
console.log(`For message ${message.messageId}. Moving`)
return imap.move(message.messageId, toFolderId)
}