From 157c048ca034d89b7ff607baac0a7085066c2b9d Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 28 Aug 2015 16:24:05 -0400 Subject: [PATCH] feat(sync): Resume sync worker action from sidebar --- .../notifications/lib/activity-sidebar.cjsx | 2 +- .../worker-sync/lib/nylas-sync-worker.coffee | 8 +++++++- .../worker-sync/spec/nylas-sync-worker-spec.coffee | 14 +++++++++++++- src/flux/actions.coffee | 13 ++++++++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/internal_packages/notifications/lib/activity-sidebar.cjsx b/internal_packages/notifications/lib/activity-sidebar.cjsx index 194d51d78..47efa997c 100644 --- a/internal_packages/notifications/lib/activity-sidebar.cjsx +++ b/internal_packages/notifications/lib/activity-sidebar.cjsx @@ -105,7 +105,7 @@ class ActivitySidebar extends React.Component _onTryAgain: => - # TODO + Actions.retryInitialSync() _onDataChanged: => @setState(@_getStateFromStores()) diff --git a/internal_packages/worker-sync/lib/nylas-sync-worker.coffee b/internal_packages/worker-sync/lib/nylas-sync-worker.coffee index 598e19b96..9ca01b726 100644 --- a/internal_packages/worker-sync/lib/nylas-sync-worker.coffee +++ b/internal_packages/worker-sync/lib/nylas-sync-worker.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -{DatabaseStore} = require 'nylas-exports' +{Actions, DatabaseStore} = require 'nylas-exports' NylasLongConnection = require './nylas-long-connection' PAGE_SIZE = 250 @@ -45,6 +45,8 @@ class NylasSyncWorker # indirection needed so resumeFetches can be spied on @resumeFetches() + @_unlisten = Actions.retryInitialSync.listen(@_onRetryInitialSync, @) + @_state = null DatabaseStore.findJSONObject("NylasSyncWorker:#{@_account.id}").then (json) => @_state = json ? {} @@ -76,6 +78,7 @@ class NylasSyncWorker @resumeFetches() cleanup: -> + @_unlisten?() @_resumeTimer.cancel() @_connection.end() @_terminated = true @@ -160,4 +163,7 @@ class NylasSyncWorker ,100 @_writeState() + _onRetryInitialSync: => + @resumeFetches() + NylasSyncWorker.BackoffTimer = BackoffTimer diff --git a/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee b/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee index 4476e5885..f9a044172 100644 --- a/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee +++ b/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -{DatabaseStore, Account, Thread} = require 'nylas-exports' +{Actions, DatabaseStore, Account, Thread} = require 'nylas-exports' NylasLongConnection = require '../lib/nylas-long-connection' NylasSyncWorker = require '../lib/nylas-sync-worker' @@ -221,6 +221,18 @@ describe "NylasSyncWorker", -> @request.requestOptions.error(new Error("Oh no a network error")) expect(@apiRequests.length).toBe(0) + it "resumes when a action forces it to", -> + err = new Error("Oh no a network error") + @request.requestOptions.error(err) + expect(@worker.state().threads.busy).toEqual(false) + expect(@worker.state().threads.complete).toEqual(false) + spyOn(@worker, 'resumeFetches').andCallThrough() + Actions.retryInitialSync() + expect(@worker.resumeFetches).toHaveBeenCalled() + expect(@worker.resumeFetches.calls.length).toBe 1 + expect(@worker.state().threads.busy).toEqual(true) + expect(@worker.state().threads.error).toBe(null) + describe "cleanup", -> it "should termiate the long polling connection", -> spyOn(@connection, 'end') diff --git a/src/flux/actions.coffee b/src/flux/actions.coffee index 5846c7339..d298b887f 100644 --- a/src/flux/actions.coffee +++ b/src/flux/actions.coffee @@ -94,7 +94,7 @@ class Actions ### Public: Queue a {Task} object to the {TaskQueue}. - *Scope: Main Window* + *Scope: Work Window* ### @queueTask: ActionScopeWorkWindow @@ -103,7 +103,7 @@ class Actions ### Public: Dequeue all {Task}s from the {TaskQueue}. Use with care. - *Scope: Main Window* + *Scope: Work Window* ### @dequeueAllTasks: ActionScopeWorkWindow @dequeueTask: ActionScopeWorkWindow @@ -111,7 +111,7 @@ class Actions ### Public: Dequeue a {Task} matching the description provided. - *Scope: Main Window* + *Scope: Work Window* ### @dequeueMatchingTask: ActionScopeWorkWindow @@ -123,6 +123,13 @@ class Actions @didMakeAPIRequest: ActionScopeWorkWindow @sendFeedback: ActionScopeWorkWindow + ### + Public: Retry the initial sync + + *Scope: Work Window* + ### + @retryInitialSync: ActionScopeWorkWindow + ### Public: Show the developer console for the current window.