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

HUE-9187 [editor] Prevent error message from expired queries in the history in editor v2

Johan Ahlen 5 жил өмнө
parent
commit
fab7f90b30

+ 21 - 6
desktop/core/src/desktop/js/api/apiHelper.js

@@ -1979,12 +1979,27 @@ class ApiHelper {
     return this.simplePost('/notebook/api/close_session', data, options);
   }
 
-  // Used by check history status
-  checkStatus(options) {
-    const data = {
-      notebook: options.notebookJson
-    };
-    return this.simplePost('/notebook/api/check_status', data);
+  async checkStatus(options) {
+    return new Promise((resolve, reject) => {
+      const data = {
+        notebook: options.notebookJson
+      };
+      $.post({
+        url: '/notebook/api/check_status',
+        data: data
+      })
+        .done(data => {
+          // 0, -3 and other negative values have meaning for this endpoint
+          if (data && typeof data.status !== 'undefined') {
+            resolve(data);
+          } else if (this.successResponseIsError(data)) {
+            reject(this.assistErrorCallback(options)(data));
+          } else {
+            reject();
+          }
+        })
+        .fail(this.assistErrorCallback(options));
+    });
   }
 
   getExternalStatement(options) {

+ 23 - 27
desktop/core/src/desktop/js/apps/notebook2/components/ko.queryHistory.js

@@ -301,42 +301,38 @@ class QueryHistory extends DisposableComponent {
       .filter(item => statusIndex[item.status()])
       .slice(0, 25);
 
-    const refreshStatusForItem = item => {
+    const refreshStatusForItem = async item => {
       if (this.refreshStatusFailed) {
         return;
       }
-      apiHelper
-        .checkStatus({
+      try {
+        const response = await apiHelper.checkStatus({
           notebookJson: JSON.stringify({ uuid: item.uuid }),
           silenceErrors: true
-        })
-        .then(data => {
-          if (data.status === -3) {
-            item.status(EXECUTION_STATUS.expired);
-          } else if (data.status !== 0) {
-            item.status(EXECUTION_STATUS.failed);
-          } else if (data.query_status.status) {
-            item.status(data.query_status.status);
-          }
-        })
-        .fail(() => {
-          items.length = 0;
-          this.refreshStatusFailed = true;
-          console.warn('Failed checking status for the history items.');
-        })
-        .always(async () => {
-          if (items.length) {
-            await sleep(1000);
-            refreshStatusForItem(items.pop());
-          } else if (!this.refreshStatusFailed) {
-            await sleep(interval);
-            this.refreshStatus(statusesToRefresh, interval);
-          }
         });
+        if (response.status === -3) {
+          item.status(EXECUTION_STATUS.expired);
+        } else if (response.status !== 0) {
+          item.status(EXECUTION_STATUS.failed);
+        } else if (response.query_status.status) {
+          item.status(response.query_status.status);
+        }
+      } catch (err) {
+        items.length = 0;
+        this.refreshStatusFailed = true;
+      } finally {
+        if (items.length) {
+          await sleep(1000);
+          await refreshStatusForItem(items.pop());
+        } else if (!this.refreshStatusFailed) {
+          await sleep(interval);
+          this.refreshStatus(statusesToRefresh, interval);
+        }
+      }
     };
 
     if (items.length) {
-      refreshStatusForItem(items.pop());
+      await refreshStatusForItem(items.pop());
     } else if (!this.refreshStatusFailed) {
       await sleep(interval);
       this.refreshStatus(statusesToRefresh, interval);