浏览代码

fix: restore back to the previous impl on pause and add instruments

Tienson Qin 2 年之前
父节点
当前提交
7911efec1c
共有 1 个文件被更改,包括 10 次插入6 次删除
  1. 10 6
      src/main/frontend/fs/sync.cljs

+ 10 - 6
src/main/frontend/fs/sync.cljs

@@ -2753,7 +2753,7 @@
 
 
   (idle [this]
   (idle [this]
     (go
     (go
-      (let [{:keys [stop remote->local local->remote local->remote-full-sync remote->local-full-sync pause]}
+      (let [{:keys [stop remote->local local->remote local->remote-full-sync remote->local-full-sync pause] :as result}
             (<! ops-chan)]
             (<! ops-chan)]
         (cond
         (cond
           stop
           stop
@@ -2768,10 +2768,12 @@
           (<! (.schedule this ::remote->local-full-sync nil nil))
           (<! (.schedule this ::remote->local-full-sync nil nil))
           pause
           pause
           (<! (.schedule this ::pause nil nil))
           (<! (.schedule this ::pause nil nil))
-          (= state ::idle)
-          nil
           :else
           :else
-          (<! (.schedule this ::stop nil nil))))))
+          (do
+            (state/pub-event! [:instrument {:type :sync/wrong-ops-chan-when-idle
+                                            :payload {:ops-chan-result result
+                                                      :state state}}])
+            nil)))))
 
 
   (full-sync [this]
   (full-sync [this]
     (go
     (go
@@ -3142,8 +3144,8 @@
 
 
                (mobile-util/native-ios?)
                (mobile-util/native-ios?)
                (let [*task-id (atom nil)]
                (let [*task-id (atom nil)]
-                 (restart-if-stopped! is-active?)
-                 (when-not is-active?
+                 (if is-active?
+                   (restart-if-stopped! is-active?)
                    (when (state/get-current-file-sync-graph-uuid)
                    (when (state/get-current-file-sync-graph-uuid)
                      (p/let [task-id (.beforeExit ^js BackgroundTask
                      (p/let [task-id (.beforeExit ^js BackgroundTask
                                                   (fn []
                                                   (fn []
@@ -3154,6 +3156,8 @@
                                                       (<! (<sync-local->remote-now))
                                                       (<! (<sync-local->remote-now))
                                                       ;; wait at most 20s
                                                       ;; wait at most 20s
                                                       (async/alts! [finished-local->remote-chan (timeout 20000)])
                                                       (async/alts! [finished-local->remote-chan (timeout 20000)])
+                                                      (offer! pause-resume-chan is-active?)
+                                                      (<! (timeout 5000))
                                                       (prn "finish task: " @*task-id)
                                                       (prn "finish task: " @*task-id)
                                                       (let [opt #js {:taskId @*task-id}]
                                                       (let [opt #js {:taskId @*task-id}]
                                                         (.finish ^js BackgroundTask opt)))))]
                                                         (.finish ^js BackgroundTask opt)))))]