mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-06 11:16:10 +08:00
Clean up loggin
This commit is contained in:
parent
bdfee404e5
commit
d26824771d
3 changed files with 2 additions and 27 deletions
|
@ -257,15 +257,11 @@ class IMAPConnection extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
runOperation(operation) {
|
runOperation(operation) {
|
||||||
console.log("Running operation")
|
|
||||||
console.log(operation.constructor.name)
|
|
||||||
if (!this._imap) {
|
if (!this._imap) {
|
||||||
throw new Error(`IMAPConnection::runOperation - You need to call connect() first.`)
|
throw new Error(`IMAPConnection::runOperation - You need to call connect() first.`)
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._queue.push({operation, resolve, reject});
|
this._queue.push({operation, resolve, reject});
|
||||||
console.log("Pushing onto queue")
|
|
||||||
console.log(this._currentOperation)
|
|
||||||
if (this._imap.state === 'authenticated' && !this._currentOperation) {
|
if (this._imap.state === 'authenticated' && !this._currentOperation) {
|
||||||
this.processNextOperation();
|
this.processNextOperation();
|
||||||
}
|
}
|
||||||
|
@ -273,33 +269,29 @@ class IMAPConnection extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
processNextOperation() {
|
processNextOperation() {
|
||||||
console.log("Process next operation")
|
|
||||||
console.log(this._currentOperation)
|
|
||||||
if (this._currentOperation) { return }
|
if (this._currentOperation) { return }
|
||||||
this._currentOperation = this._queue.shift();
|
this._currentOperation = this._queue.shift();
|
||||||
if (!this._currentOperation) {
|
if (!this._currentOperation) {
|
||||||
console.log("queue empty")
|
|
||||||
this.emit('queue-empty');
|
this.emit('queue-empty');
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const {operation, resolve, reject} = this._currentOperation;
|
const {operation, resolve, reject} = this._currentOperation;
|
||||||
console.log(`Starting task ${operation.description()}`)
|
|
||||||
const result = operation.run(this._db, this);
|
const result = operation.run(this._db, this);
|
||||||
console.log(`have operation promise`)
|
|
||||||
if (result instanceof Promise === false) {
|
if (result instanceof Promise === false) {
|
||||||
reject(new NylasError(`Expected ${operation.constructor.name} to return promise.`))
|
reject(new NylasError(`Expected ${operation.constructor.name} to return promise.`))
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this._currentOperation = null;
|
this._currentOperation = null;
|
||||||
console.log(`Finished task ${operation.description()}`)
|
console.log(`Finished task: ${operation.description()}`)
|
||||||
resolve();
|
resolve();
|
||||||
this.processNextOperation();
|
this.processNextOperation();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this._currentOperation = null;
|
this._currentOperation = null;
|
||||||
console.log(`Task errored: ${operation.description()}`)
|
console.log(`Task errored: ${operation.description()}`)
|
||||||
|
console.error(err)
|
||||||
reject(err);
|
reject(err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ class SyncWorker {
|
||||||
this.syncNow();
|
this.syncNow();
|
||||||
|
|
||||||
this._onMessage = this._onMessage.bind(this);
|
this._onMessage = this._onMessage.bind(this);
|
||||||
console.log("SYNC WORKER -------------------")
|
|
||||||
this._listener = PubsubConnector.observe(account.id).subscribe(this._onMessage)
|
this._listener = PubsubConnector.observe(account.id).subscribe(this._onMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +40,7 @@ class SyncWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMessage(msg) {
|
_onMessage(msg) {
|
||||||
console.log("============= ON MESSAGE")
|
|
||||||
console.log(msg)
|
|
||||||
const {type} = JSON.parse(msg);
|
const {type} = JSON.parse(msg);
|
||||||
console.log(type)
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MessageTypes.ACCOUNT_UPDATED:
|
case MessageTypes.ACCOUNT_UPDATED:
|
||||||
this._onAccountUpdated(); break;
|
this._onAccountUpdated(); break;
|
||||||
|
@ -100,7 +96,6 @@ class SyncWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureConnection() {
|
ensureConnection() {
|
||||||
console.log("ENSURING CONNECTION")
|
|
||||||
if (this._conn) {
|
if (this._conn) {
|
||||||
return this._conn.connect();
|
return this._conn.connect();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +124,6 @@ class SyncWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
syncbackMessageActions() {
|
syncbackMessageActions() {
|
||||||
console.log("SYNCBACK MESSAGE ACTIONS")
|
|
||||||
const where = {where: {status: "NEW"}, limit: 100};
|
const where = {where: {status: "NEW"}, limit: 100};
|
||||||
return this._db.SyncbackRequest.findAll(where)
|
return this._db.SyncbackRequest.findAll(where)
|
||||||
.map((req) => SyncbackTaskFactory.create(this._account, req))
|
.map((req) => SyncbackTaskFactory.create(this._account, req))
|
||||||
|
@ -140,20 +134,15 @@ class SyncWorker {
|
||||||
const syncbackRequest = task.syncbackRequestObject()
|
const syncbackRequest = task.syncbackRequestObject()
|
||||||
return this._conn.runOperation(task)
|
return this._conn.runOperation(task)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`Task succeeded: ${task.constructor.name}`)
|
|
||||||
syncbackRequest.status = "SUCCEEDED"
|
syncbackRequest.status = "SUCCEEDED"
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(`Task errored`)
|
|
||||||
console.error(error)
|
|
||||||
console.error(error.message)
|
|
||||||
syncbackRequest.error = error
|
syncbackRequest.error = error
|
||||||
syncbackRequest.status = "FAILED"
|
syncbackRequest.status = "FAILED"
|
||||||
}).finally(() => syncbackRequest.save())
|
}).finally(() => syncbackRequest.save())
|
||||||
}
|
}
|
||||||
|
|
||||||
syncAllCategories() {
|
syncAllCategories() {
|
||||||
console.log("Syncing all categories")
|
|
||||||
const {Category} = this._db;
|
const {Category} = this._db;
|
||||||
const {folderSyncOptions} = this._account.syncPolicy;
|
const {folderSyncOptions} = this._account.syncPolicy;
|
||||||
|
|
||||||
|
@ -170,18 +159,14 @@ class SyncWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
performSync() {
|
performSync() {
|
||||||
console.log("Performing sync")
|
|
||||||
return this._conn.runOperation(new FetchCategoryList(this._account.provider))
|
return this._conn.runOperation(new FetchCategoryList(this._account.provider))
|
||||||
.then(() => this.syncbackMessageActions())
|
.then(() => this.syncbackMessageActions())
|
||||||
.then(() => this.syncAllCategories())
|
.then(() => this.syncAllCategories())
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNow() {
|
syncNow() {
|
||||||
console.log("SYNCING NOW")
|
|
||||||
clearTimeout(this._syncTimer);
|
clearTimeout(this._syncTimer);
|
||||||
|
|
||||||
console.log(process.env.SYNC_AFTER_ERRORS)
|
|
||||||
console.log(this._account.errored())
|
|
||||||
if (!process.env.SYNC_AFTER_ERRORS && 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`)
|
console.log(`SyncWorker: Account ${this._account.emailAddress} is in error state - Skipping sync`)
|
||||||
return
|
return
|
||||||
|
|
|
@ -7,12 +7,10 @@ class MoveToFolderIMAP extends SyncbackTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
run(db, imap) {
|
run(db, imap) {
|
||||||
console.log("------------------ RUNNING MOVE TO FOLDER IMAP")
|
|
||||||
const threadId = this.syncbackRequestObject().props.threadId
|
const threadId = this.syncbackRequestObject().props.threadId
|
||||||
const toFolderId = this.syncbackRequestObject().props.folderId
|
const toFolderId = this.syncbackRequestObject().props.folderId
|
||||||
|
|
||||||
const eachMsg = ({message}) => {
|
const eachMsg = ({message}) => {
|
||||||
console.log(`For message ${message.messageId}. Moving`)
|
|
||||||
return imap.move(message.messageId, toFolderId)
|
return imap.move(message.messageId, toFolderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue