Pārlūkot izejas kodu

HUE-9001 [editor] Improve executor logic in notebook 2 when failing

Johan Ahlen 6 gadi atpakaļ
vecāks
revīzija
55d387f46a
1 mainītis faili ar 28 papildinājumiem un 21 dzēšanām
  1. 28 21
      desktop/core/src/desktop/js/apps/notebook2/snippet.js

+ 28 - 21
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -203,6 +203,8 @@ class Snippet {
 
     self.errors = ko.observableArray([]);
 
+    self.executor = ko.observable();
+
     self.aceErrorsHolder = ko.observableArray([]);
     self.aceWarningsHolder = ko.observableArray([]);
 
@@ -1115,12 +1117,10 @@ class Snippet {
       timeout: self.parentVm.autocompleteTimeout
     });
 
-    self.executor = undefined;
-
     huePubSub.subscribe('hue.executor.updated', details => {
       const executable = details.executable;
 
-      if (details.executor === self.executor) {
+      if (details.executor === self.executor()) {
         self.status(executable.status);
         self.progress(executable.progress);
       }
@@ -1339,7 +1339,7 @@ class Snippet {
     });
   }
 
-  execute(automaticallyTriggered) {
+  async execute(automaticallyTriggered) {
     hueAnalytics.log('notebook', 'execute/' + this.type());
 
     const now = new Date().getTime();
@@ -1381,28 +1381,35 @@ class Snippet {
 
     this.currentQueryTab('queryHistory');
 
-    if (this.executor && this.executor.isRunning()) {
-      this.executor.cancel();
+    if (this.executor() && this.executor().isRunning()) {
+      this.executor().cancel();
     }
 
-    this.executor = new Executor({
-      compute: this.compute(),
-      database: this.database(),
-      sourceType: this.type(),
-      namespace: this.namespace(),
-      statement: this.statement(),
-      isSqlEngine: this.isSqlDialect()
-    });
+    this.executor(
+      new Executor({
+        compute: this.compute(),
+        database: this.database(),
+        sourceType: this.type(),
+        namespace: this.namespace(),
+        statement: this.statement(),
+        isSqlEngine: this.isSqlDialect()
+      })
+    );
+
+    try {
+      const result = await this.executor().executeNext();
 
-    this.executor.executeNext().then(executionResult => {
       this.stopLongOperationTimeout();
       this.result.clear();
-      this.result.update(executionResult).then(() => {
-        if (this.result.data().length) {
-          this.currentQueryTab('queryResults');
-        }
-      });
-    });
+
+      await this.result.update(result);
+
+      if (this.result.data().length) {
+        this.currentQueryTab('queryResults');
+      }
+    } catch (error) {
+      this.stopLongOperationTimeout();
+    }
   }
 
   explain() {