Cleanup syncback task

This commit is contained in:
Evan Morikawa 2016-06-28 19:02:12 -07:00
parent c7422ffaea
commit 11a3a8f58e

View file

@ -40,7 +40,7 @@ class SyncWorker {
} }
_onMessage(msg) { _onMessage(msg) {
const {type, data} = JSON.parse(msg) const {type} = JSON.parse(msg)
switch (type) { switch (type) {
case MessageTypes.ACCOUNT_UPDATED: case MessageTypes.ACCOUNT_UPDATED:
this._onAccountUpdated(); break; this._onAccountUpdated(); break;
@ -127,7 +127,19 @@ class SyncWorker {
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))
.each(this._conn.runOperation) .each(this.runSyncbackTask.bind(this))
}
runSyncbackTask(task) {
return this._conn.runOperation(task)
.then(() => {
task.syncbackRequest.status = "SUCCEEDED"
}).catch((error) => {
task.syncbackRequest.error = error
task.syncbackRequest.status = "FAILED"
}).finally(() => {
return task.syncbackRequest.save()
})
} }
syncAllCategories() { syncAllCategories() {