Эх сурвалжийг харах

HUE-8768 [editor] Switch to backend execution status for notebook 2

Johan Ahlen 6 жил өмнө
parent
commit
13518086cb

+ 13 - 18
desktop/core/src/desktop/js/apps/notebook2/execution/executableStatement.js

@@ -19,22 +19,19 @@ import { ExecutionResult } from 'apps/notebook2/execution/executionResult';
 import hueAnalytics from 'utils/hueAnalytics';
 
 /**
- *  ready +----> executing +----> done +----> closed
- *                   +     |
- *                   |     +----> fail
- *                   |
- *                   +----> canceling +----> canceled
- *
  * @type { { canceling: string, canceled: string, fail: string, ready: string, executing: string, done: string } }
  */
 const EXECUTION_STATUS = {
+  available: 'available',
+  success: 'success',
+  expired: 'expired',
+  running: 'running',
+  starting: 'starting',
+  waiting: 'waiting',
   ready: 'ready',
-  executing: 'executing',
   canceled: 'canceled',
   canceling: 'canceling',
-  closed: 'closed',
-  done: 'done',
-  fail: 'fail'
+  closed: 'closed'
 };
 
 class ExecutableStatement {
@@ -85,7 +82,8 @@ class ExecutableStatement {
           this.lastCancellable = apiHelper
             .checkExecutionStatus({ executable: this })
             .done(queryStatus => {
-              switch (queryStatus) {
+              this.status = queryStatus;
+              switch (this.status) {
                 case 'success':
                   this.progress = 99; // TODO: why 99 here (from old code)?
                   statusResolve();
@@ -122,7 +120,7 @@ class ExecutableStatement {
         });
 
       hueAnalytics.log('notebook', 'execute/' + this.sourceType);
-      this.status = EXECUTION_STATUS.executing;
+      this.status = EXECUTION_STATUS.running;
 
       this.lastCancellable = apiHelper
         .executeStatement({
@@ -134,16 +132,13 @@ class ExecutableStatement {
           checkStatus()
             .then(() => {
               this.result = new ExecutionResult(this);
-              this.status = EXECUTION_STATUS.done;
               resolve(this.result);
             })
             .catch(error => {
-              this.status = EXECUTION_STATUS.fail;
               reject(error);
             });
         })
         .fail(error => {
-          this.status = EXECUTION_STATUS.fail;
           reject(error);
         });
     });
@@ -151,7 +146,7 @@ class ExecutableStatement {
 
   async cancel() {
     return new Promise(resolve => {
-      if (this.lastCancellable && this.status === EXECUTION_STATUS.executing) {
+      if (this.lastCancellable && this.status === EXECUTION_STATUS.running) {
         hueAnalytics.log('notebook', 'cancel/' + this.sourceType);
         this.status = EXECUTION_STATUS.canceling;
         this.lastCancellable.cancel().always(() => {
@@ -167,9 +162,9 @@ class ExecutableStatement {
 
   async close() {
     return new Promise(resolve => {
-      if (this.status === EXECUTION_STATUS.executing) {
+      if (this.status === EXECUTION_STATUS.running) {
         this.cancel().finally(resolve);
-      } else if (this.status === EXECUTION_STATUS.done) {
+      } else if (this.status !== EXECUTION_STATUS.closed) {
         apiHelper.closeStatement({ executable: this }).finally(resolve);
       }
     }).finally(() => {

+ 5 - 1
desktop/core/src/desktop/js/apps/notebook2/execution/executor.js

@@ -98,8 +98,12 @@ class Executor {
     huePubSub.publish('hue.executor.progress.updated', this);
   }
 
+  isRunning() {
+    return this.currentExecutable && this.currentExecutable.status === EXECUTION_STATUS.running;
+  }
+
   async cancel() {
-    if (this.currentExecutable && this.currentExecutable.status === EXECUTION_STATUS.running) {
+    if (this.isRunning()) {
       this.setStatus(EXECUTION_STATUS.canceling);
       return await this.currentExecutable.cancel();
     }

+ 3 - 1
desktop/core/src/desktop/js/apps/notebook2/result.js

@@ -17,7 +17,9 @@
 import ko from 'knockout';
 
 import hueUtils from 'utils/hueUtils';
-import huePubSub from '../../utils/huePubSub';
+import huePubSub from 'utils/huePubSub';
+
+import { EXECUTION_STATUS } from 'apps/notebook2/execution/executableStatement';
 
 const adaptMeta = meta => {
   meta.forEach((item, index) => {