mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-05 04:04:38 +08:00
[client-sync] Fix the new syncback-task structure
Summary: - Change files to .es6 so they recognize the syntax - Pass arguments down to _run() - Make sure the responses get returned Test Plan: manual, even though that somehow failed before. :( Reviewers: evan, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D4309
This commit is contained in:
parent
13ac2fa3b4
commit
c6a339df1a
22 changed files with 30 additions and 22 deletions
|
@ -691,7 +691,7 @@ class FetchMessagesInFolderIMAP extends SyncTask {
|
|||
* we want to interrupt sync. This is enabled by `SyncOperation` and
|
||||
* `Interruptible`
|
||||
*/
|
||||
async * runTask(db, imap, syncWorker) {
|
||||
async * runTask(db, imap, {syncWorker} = {}) {
|
||||
this._logger.log(`🔜 📂 ${this._folder.name}`)
|
||||
this._db = db;
|
||||
this._imap = imap;
|
||||
|
|
|
@ -13,7 +13,7 @@ class FetchNewMessagesInFolderIMAP extends FetchMessagesInFolderIMAP {
|
|||
return `FetchNewMessagesInFolderIMAP (${this._folder.name} - ${this._folder.id})`;
|
||||
}
|
||||
|
||||
async * runTask(db, imap, syncWorker) {
|
||||
async * runTask(db, imap, {syncWorker} = {}) {
|
||||
this._logger.log(`🔜 📂 🆕 ${this._folder.name} - Looking for new messages`)
|
||||
this._db = db;
|
||||
this._imap = imap;
|
||||
|
|
|
@ -8,7 +8,7 @@ class FetchSpecificMessagesInFolderIMAP extends FetchMessagesInFolderIMAP {
|
|||
return `FetchSpecificMessagesInFolderIMAP (${this._folder.name} - ${this._folder.id})`;
|
||||
}
|
||||
|
||||
async * runTask(db, imap, syncWorker) {
|
||||
async * runTask(db, imap, {syncWorker} = {}) {
|
||||
this._logger.log(`🔜 📂 🆕 ${this._folder.name} - Looking for ${this._uids.length} specific UIDs`);
|
||||
this._db = db;
|
||||
this._imap = imap;
|
||||
|
|
|
@ -168,7 +168,7 @@ class SyncbackTaskRunner {
|
|||
let responseJSON;
|
||||
switch (resource) {
|
||||
case 'imap':
|
||||
responseJSON = await this._imap.runOperation(task, this._syncWorker)
|
||||
responseJSON = await this._imap.runOperation(task, {syncWorker: this._syncWorker})
|
||||
break;
|
||||
case 'smtp':
|
||||
responseJSON = await task.run(this._db, this._smtp)
|
||||
|
|
|
@ -136,7 +136,7 @@ class EnsureMessageInSentFolderIMAP extends SyncbackIMAPTask {
|
|||
return false
|
||||
}
|
||||
|
||||
async * _run(db, imap, syncWorker) {
|
||||
async * _run(db, imap, {syncWorker} = {}) {
|
||||
const {Message} = db
|
||||
const {messageId, customSentMessage} = this.syncbackRequestObject().props
|
||||
|
|
@ -12,7 +12,7 @@ class MoveThreadToFolderIMAP extends SyncbackIMAPTask {
|
|||
return true
|
||||
}
|
||||
|
||||
async * _run(db, imap, syncWorker) {
|
||||
async * _run(db, imap, {syncWorker} = {}) {
|
||||
const {Thread, Folder} = db
|
||||
const threadId = this.syncbackRequestObject().props.threadId
|
||||
const targetFolderId = this.syncbackRequestObject().props.folderId
|
|
@ -14,7 +14,7 @@ class SetThreadFolderAndLabelsIMAP extends SyncbackIMAPTask {
|
|||
}
|
||||
|
||||
|
||||
async * _run(db, imap, syncWorker) {
|
||||
async * _run(db, imap, {syncWorker} = {}) {
|
||||
const {Thread, Folder} = db
|
||||
const threadId = this.syncbackRequestObject().props.threadId
|
||||
const labelIds = this.syncbackRequestObject().props.labelIds
|
|
@ -14,7 +14,7 @@ class SyncUnknownUIDs extends SyncbackIMAPTask {
|
|||
return false;
|
||||
}
|
||||
|
||||
async * _run(db, imap, syncWorker) {
|
||||
async * _run(db, imap, {syncWorker} = {}) {
|
||||
this._db = db;
|
||||
const {Folder} = db
|
||||
const {uids, folderId} = this.syncbackRequestObject().props;
|
|
@ -49,19 +49,25 @@ class SyncbackTask {
|
|||
throw new Error("Must implement a _run method")
|
||||
}
|
||||
|
||||
async run({timeoutDelay = TIMEOUT_DELAY} = {}) {
|
||||
async run(db, imapOrSmtp, ctx = {}) {
|
||||
const {timeoutDelay = TIMEOUT_DELAY} = ctx
|
||||
const timeout = setTimeout(this.stop, timeoutDelay)
|
||||
const startTime = Date.now()
|
||||
await this._interruptible.run(this._run)
|
||||
Actions.recordPerfMetric({
|
||||
action: 'syncback-task-run',
|
||||
accountId: this._account.id,
|
||||
actionTimeMs: Date.now() - startTime,
|
||||
maxValue: 10 * 60 * 1000,
|
||||
type: this._syncbackRequest.type,
|
||||
provider: this._account.provider,
|
||||
})
|
||||
clearTimeout(timeout)
|
||||
const response = await this._interruptible.run(() => this._run(db, imapOrSmtp, ctx))
|
||||
try {
|
||||
Actions.recordPerfMetric({
|
||||
action: 'syncback-task-run',
|
||||
accountId: this._account.id,
|
||||
actionTimeMs: Date.now() - startTime,
|
||||
maxValue: 10 * 60 * 1000,
|
||||
type: this._syncbackRequest.type,
|
||||
provider: this._account.provider,
|
||||
})
|
||||
clearTimeout(timeout)
|
||||
} catch (err) {
|
||||
// Do nothing
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,20 +124,22 @@ class Interruptible extends EventEmitter {
|
|||
async run(generatorFunc, ctx, ...fnArgs) {
|
||||
this._running = true
|
||||
const generatorObj = generatorFunc.call(ctx, ...fnArgs)
|
||||
await new Promise(async (resolve, reject) => {
|
||||
const response = await new Promise(async (resolve, reject) => {
|
||||
this._rejectWithinRun = (rejectValue) => {
|
||||
reject(rejectValue)
|
||||
}
|
||||
let _response;
|
||||
try {
|
||||
await this._runGenerator(generatorObj)
|
||||
_response = await this._runGenerator(generatorObj)
|
||||
} catch (err) {
|
||||
reject(err)
|
||||
return;
|
||||
}
|
||||
resolve()
|
||||
resolve(_response)
|
||||
})
|
||||
this._interrupt = false
|
||||
this._running = false
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue