Răsfoiți Sursa

HUE-4242 [editor] Offer retries when submission or result fetching timed out

Romain Rigaux 9 ani în urmă
părinte
comite
d865e610e0

+ 4 - 0
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -38,6 +38,10 @@ class QueryExpired(Exception):
 class AuthenticationRequired(Exception):
   pass
 
+class OperationTimeout(Exception):
+  pass
+
+
 class QueryError(Exception):
   def __init__(self, message, handle=None):
     self.message = message or _('No error message, please check the logs.')

+ 9 - 2
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -24,12 +24,13 @@ from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
 
 from desktop.conf import USE_DEFAULT_CONFIGURATION
-from desktop.lib.conf import BoundConfig, Config
+from desktop.lib.conf import BoundConfig
+from desktop.lib.exceptions import StructuredException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import force_unicode
 from desktop.models import DefaultConfiguration
 
-from notebook.connectors.base import Api, QueryError, QueryExpired
+from notebook.connectors.base import Api, QueryError, QueryExpired, OperationTimeout
 
 
 LOG = logging.getLogger(__name__)
@@ -64,6 +65,12 @@ def query_error_handler(func):
   def decorator(*args, **kwargs):
     try:
       return func(*args, **kwargs)
+    except StructuredException, e:
+      message = force_unicode(str(e))
+      if 'timed out' in message:
+        raise OperationTimeout(e)
+      else:
+        raise QueryError(message)
     except QueryServerException, e:
       message = force_unicode(str(e))
       if 'Invalid query handle' in message or 'Invalid OperationHandle' in message:

+ 3 - 1
desktop/libs/notebook/src/notebook/decorators.py

@@ -28,7 +28,7 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import smart_unicode
 from desktop.models import Document2, Document
 
-from notebook.connectors.base import QueryExpired, QueryError, SessionExpired, AuthenticationRequired
+from notebook.connectors.base import QueryExpired, QueryError, SessionExpired, AuthenticationRequired, OperationTimeout
 
 
 LOG = logging.getLogger(__name__)
@@ -89,6 +89,8 @@ def api_error_handler(func):
       LOG.exception('Error validation %s' % func)
       response['status'] = -1
       response['message'] = e.message
+    except OperationTimeout, e:
+      response['status'] = -4
     except QueryError, e:
       LOG.exception('Error running %s' % func)
       response['status'] = 1

+ 8 - 1
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -647,6 +647,13 @@
       else if (data.status == -3) { // Statement expired
         self.status('expired');
       }
+      else if (data.status == -4) { // Operation timed out
+        self.status('failed'); // to remove when below ready
+        ///
+        console.log('Operation timed out, do you want to retry or cancel?'); // cf. 401 modal below for popup or inline message same place as usual error message? (nicer than popup)
+        // if yes, if (callback) { callback(); };
+        // if no, self.status('failed');
+      }
       else if (data.status == 401) { // Auth required
         self.status('expired');
         $(document).trigger("showAuthModal", {'type': self.type(), 'callback': self.execute});
@@ -901,7 +908,7 @@
           if (data.status == 0) {
             self.loadData(data.result, rows);
           } else {
-            self._ajaxError(data);
+            self._ajaxError(data, function() {self.isFetchingData = false; self.fetchResultData(rows, startOver); });
             $(document).trigger("renderDataError", {snippet: self});
           }
         }, 'text').fail(function (xhr, textStatus, errorThrown) {