Ver Fonte

HUE-3214 [editor] Persist status of a running query

Romain Rigaux há 9 anos atrás
pai
commit
83a27a3

+ 15 - 3
desktop/libs/notebook/src/notebook/api.py

@@ -107,8 +107,20 @@ def check_status(request):
   notebook = json.loads(request.POST.get('notebook', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
 
-  response['query_status'] = get_api(request, snippet).check_status(notebook, snippet)
-  response['status'] = 0
+  try:
+    response['query_status'] = get_api(request, snippet).check_status(notebook, snippet)
+    response['status'] = 0
+  finally:
+    if response['status'] == 0 and snippet['status'] != response['query_status']:
+      status = response['query_status']['status']
+    else:
+      status = 'failed'
+    nb_doc = Document2.objects.get(id=notebook['id'])
+    nb_doc.can_write_or_exception(request.user)
+    nb = Notebook(document=nb_doc).get_data()
+    nb['snippets'][0]['status'] = status
+    nb_doc.update_data(nb)
+    nb_doc.save()
 
   return JsonResponse(response)
 
@@ -276,7 +288,7 @@ def get_history(request):
       'id': doc.id,
       'data': Notebook(document=doc).get_data(),
       'absoluteUrl': doc.get_absolute_url()
-      } for doc in Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user)[:25]]
+      } for doc in Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user).order_by('-last_modified')[:25]]
   response['message'] = _('History fetched')
 
   return JsonResponse(response)

+ 9 - 6
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -369,11 +369,13 @@
       });
       return statement;
     });
-    this.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 5000 } });
-    this.delayedStatement.subscribe(function (val) {
-      self.getComplexity();
-      self.hasSuggestion(false);
-    }, this);
+    if (vm.isOptimizerEnabled()) {
+      self.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 5000 } });
+      self.delayedStatement.subscribe(function (val) {
+        self.getComplexity();
+        self.hasSuggestion(false);
+      }, self);
+    }
 
     self.result = new Result(snippet, snippet.result);
     self.showGrid = ko.observable(typeof snippet.showGrid != "undefined" && snippet.showGrid != null ? snippet.showGrid : true);
@@ -605,8 +607,9 @@
         } else {
           self._ajaxError(data, self.execute);
         }
-        if (vm.editorMode && data.history_id){
+        if (vm.editorMode && data.history_id) {
           hueUtils.changeURL('/notebook/editor?editor=' + data.history_id);
+          self.id(data.history_id);
         }
       }).fail(function (xhr, textStatus, errorThrown) {
         $(document).trigger("error", xhr.responseText);