mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 10:33:14 +08:00
Add a shortcut to restart the sync for an account from scratch.
This commit is contained in:
parent
48fff4f4e1
commit
ac818f30fe
4 changed files with 34 additions and 20 deletions
|
@ -55,16 +55,13 @@ const buildAccountWith = ({name, email, provider, settings, credentials}) => {
|
|||
account.setCredentials(credentials);
|
||||
|
||||
return account.save().then((saved) =>
|
||||
AccountToken.create({accountId: saved.id}).then((token) =>
|
||||
LocalDatabaseConnector.ensureAccountDatabase(saved.id).then(() => {
|
||||
SyncProcessManager.addWorkerForAccount(saved);
|
||||
|
||||
return Promise.resolve({
|
||||
account: saved,
|
||||
token: token,
|
||||
});
|
||||
})
|
||||
)
|
||||
AccountToken.create({accountId: saved.id}).then((token) => {
|
||||
SyncProcessManager.addWorkerForAccount(saved);
|
||||
return Promise.resolve({
|
||||
account: saved,
|
||||
token: token,
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -45,7 +45,13 @@ class AccountCard extends React.Component {
|
|||
SyncProcessManager.wakeWorkerForAccount(account);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onResetSync = () => {
|
||||
SyncProcessManager.removeWorkerForAccountId(this.props.account.id);
|
||||
LocalDatabaseConnector.destroyAccountDatabase(this.props.account.id);
|
||||
SyncProcessManager.addWorkerForAccount(this.props.account);
|
||||
}
|
||||
|
||||
renderError() {
|
||||
|
@ -89,6 +95,7 @@ class AccountCard extends React.Component {
|
|||
style={{top: `${position.top}px`, left: `${position.left}px`}}
|
||||
>
|
||||
<h3>{account.emailAddress} [{account.id}]</h3>
|
||||
<button name="Reset sync" onClick={this.onResetSync}>Reset sync</button>
|
||||
<SyncbackRequestDetails accountId={account.id} />
|
||||
<div className="stats">
|
||||
<b>First Sync Duration (sec)</b>:
|
||||
|
|
|
@ -50,15 +50,18 @@ class SyncProcessManager {
|
|||
}
|
||||
|
||||
addWorkerForAccount(account) {
|
||||
return LocalDatabaseConnector.forAccount(account.id).then((db) => {
|
||||
if (this._workers[account.id]) {
|
||||
return Promise.reject(new Error("Local worker already exists"));
|
||||
}
|
||||
return LocalDatabaseConnector.ensureAccountDatabase(account.id)
|
||||
.then(() => {
|
||||
return LocalDatabaseConnector.forAccount(account.id).then((db) => {
|
||||
if (this._workers[account.id]) {
|
||||
return Promise.reject(new Error("Local worker already exists"));
|
||||
}
|
||||
|
||||
this._workers[account.id] = new SyncWorker(account, db, () => {
|
||||
this.removeWorkerForAccountId(account.id)
|
||||
});
|
||||
return Promise.resolve();
|
||||
this._workers[account.id] = new SyncWorker(account, db, () => {
|
||||
this.removeWorkerForAccountId(account.id)
|
||||
});
|
||||
return Promise.resolve();
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
this._logger.info({account_id: account.id}, `ProcessManager: Claiming Account Succeeded`)
|
||||
|
@ -69,6 +72,8 @@ class SyncProcessManager {
|
|||
}
|
||||
|
||||
removeWorkerForAccountId(accountId) {
|
||||
const worker = this._workers[accountId];
|
||||
worker.cleanup();
|
||||
this._workers[accountId] = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,12 @@ class LocalDatabaseConnector {
|
|||
|
||||
destroyAccountDatabase(accountId) {
|
||||
const dbname = `a-${accountId}`;
|
||||
fs.removeFileSync(path.join(process.env.NYLAS_HOME, `${dbname}.sqlite`));
|
||||
fs.access(dbname, fs.F_OK, (err) => {
|
||||
if (!err) {
|
||||
fs.unlinkSync(path.join(process.env.NYLAS_HOME, `${dbname}.sqlite`));
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue