Ver Fonte

[notebook] Restart polling for query status if snippet was in running state

It means that if the query is re-opened or the page refreshed, we restart polling
to where we were and display the results if/when the query finishes.
Romain Rigaux há 10 anos atrás
pai
commit
1e0b0a3

+ 23 - 25
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -802,8 +802,6 @@
           _snippet.status('loading');
           _snippet.status('loading');
           self.createSession(new Session(vm, {'type': _snippet.type()}));
           self.createSession(new Session(vm, {'type': _snippet.type()}));
         }, 200);
         }, 200);
-      } else {
-        _snippet.status('ready');
       }
       }
 
 
       _snippet.init();
       _snippet.init();
@@ -834,30 +832,30 @@
       $.post("/notebook/api/create_session", {
       $.post("/notebook/api/create_session", {
         notebook: ko.mapping.toJSON(self.getContext()),
         notebook: ko.mapping.toJSON(self.getContext()),
         session: ko.mapping.toJSON(session) // e.g. {'type': 'hive', 'properties': [{'name': driverCores', 'value', '2'}]}
         session: ko.mapping.toJSON(session) // e.g. {'type': 'hive', 'properties': [{'name': driverCores', 'value', '2'}]}
-      }, function (data) {
-        if (data.status == 0) {
-          ko.mapping.fromJS(data.session, {}, session);
-          if (self.getSession(session.type()) == null) {
-            self.addSession(session);
+        }, function (data) {
+          if (data.status == 0) {
+            ko.mapping.fromJS(data.session, {}, session);
+            if (self.getSession(session.type()) == null) {
+              self.addSession(session);
+            }
+            $.each(self.getSnippets(session.type()), function(index, snippet) {
+              snippet.status('ready');
+            });
+            if (callback) {
+              setTimeout(callback, 500);
+            }
+          } else if (data.status == 401) {
+            $(document).trigger("showAuthModal", {'type': session.type()});
           }
           }
-          $.each(self.getSnippets(session.type()), function(index, snippet) {
-            snippet.status('ready');
-          });
-          if (callback) {
-            setTimeout(callback, 500);
+          else {
+            fail(data.message);
           }
           }
-        } else if (data.status == 401) {
-          $(document).trigger("showAuthModal", {'type': session.type()});
-        }
-        else {
-          fail(data.message);
-        }
-      }).fail(function (xhr) {
-        fail(xhr.responseText);
-      }).complete(function(xhr, status) {
-        self.creatingSessionLocks.remove(session.type());
-      })
-    };
+        }).fail(function (xhr) {
+          fail(xhr.responseText);
+        }).complete(function(xhr, status) {
+          self.creatingSessionLocks.remove(session.type());
+        })
+      };
 
 
     self.authSession = function () {
     self.authSession = function () {
       self.createSession(new Session(vm, {
       self.createSession(new Session(vm, {
@@ -1125,7 +1123,7 @@
       $(document).trigger("editingToggled");
       $(document).trigger("editingToggled");
     });
     });
     self.toggleEditing = function () {
     self.toggleEditing = function () {
-      self.isEditing(!self.isEditing());
+      self.isEditing(! self.isEditing());
     };
     };
 
 
     self.authSessionUsername = ko.observable(); // UI popup
     self.authSessionUsername = ko.observable(); // UI popup

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1876,7 +1876,7 @@ ${ require.config() }
       viewModel.init();
       viewModel.init();
 
 
       if (viewModel.editorMode && !viewModel.selectedNotebook().snippets()[0].result.hasSomeResults()) {
       if (viewModel.editorMode && !viewModel.selectedNotebook().snippets()[0].result.hasSomeResults()) {
-        viewModel.selectedNotebook().showHistory(true);
+        viewModel.selectedNotebook().fetchHistory();
       }
       }
 
 
       if (location.getParameter("github_status") != "") {
       if (location.getParameter("github_status") != "") {