fix(task-queue): Save the task queue before closing the window

Summary:
Save the final state of the TaskQueue to the database before window
gets unloaded

Test Plan: Manual

Reviewers: evan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3408
This commit is contained in:
Juan Tejada 2016-11-04 15:30:26 -07:00
parent 5b1ee293dc
commit 7ac7fa58ec

View file

@ -73,6 +73,12 @@ class TaskQueue
@_restoreQueue() @_restoreQueue()
NylasEnv.onBeforeUnload((finishUnload) =>
@_saveQueue()
.finally(finishUnload)
return false
)
@listenTo Actions.queueTask, @enqueue @listenTo Actions.queueTask, @enqueue
@listenTo Actions.queueTasks, (tasks) => @listenTo Actions.queueTasks, (tasks) =>
return unless tasks and tasks.length > 0 return unless tasks and tasks.length > 0
@ -325,10 +331,14 @@ class TaskQueue
@_queue = queue @_queue = queue
@_updateSoon() @_updateSoon()
_saveQueue: =>
return DatabaseStore.inTransaction((t) =>
return t.persistJSONBlob(JSONBlobStorageKey, @_queue ? [])
)
_updateSoon: => _updateSoon: =>
@_updateSoonThrottled ?= _.throttle => @_updateSoonThrottled ?= _.throttle =>
DatabaseStore.inTransaction (t) => @_saveQueue()
t.persistJSONBlob(JSONBlobStorageKey, @_queue ? [])
_.defer => _.defer =>
@_processQueue() @_processQueue()
@_ensurePeriodicUpdates() @_ensurePeriodicUpdates()