소스 검색

HUE-9266 [history] Change job counter to be about running queries

Romain 6 년 전
부모
커밋
97324505d5

+ 7 - 2
apps/jobbrowser/src/jobbrowser/apis/history.py

@@ -58,11 +58,16 @@ class HistoryApi(Api):
           } if notebook['snippets'] else {},
           'absoluteUrl': app.get_absolute_url(),
       }
+      api_status = self._api_status(history)
+
+      if filters.get('states') and api_status.lower() not in filters['states']:
+        continue
+
       apps.append({
           'id': 'history-%010d' % history['id'],
           'name': history['data']['statement'],
           'status': history['data']['status'],
-          'apiStatus': self._api_status(history),
+          'apiStatus': api_status,
           'type': 'history-%s' % history['type'],
           'user': self.user.username,
           'progress': 50,
@@ -117,7 +122,7 @@ class HistoryApi(Api):
   def _api_status(self, task):
     if task['data']['status'] in ('expired', 'failed'):
       return 'FAILED'
-    elif task['data']['status'] == 'available':
+    elif task['data']['status'] in ('available', 'canceled'):
       return 'SUCCEEDED'
     else:
       return 'RUNNING'

+ 3 - 1
apps/jobbrowser/src/jobbrowser/templates/job_browser.mako

@@ -371,7 +371,9 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
                 <!-- /ko -->
               </form>
 
-              <div data-bind="visible: jobs.showJobCountBanner" class="pull-center alert alert-warning">${ _("Showing oldest %s jobs. Use days filter to get the recent ones.") % MAX_JOB_FETCH.get() }</div>
+              <div data-bind="visible: jobs.showJobCountBanner" class="pull-center alert alert-warning">
+                ${ _("Showing oldest %s jobs. Use days filter to get the recent ones.") % MAX_JOB_FETCH.get() }
+              </div>
 
               <div class="card card-small">
                 <!-- ko hueSpinner: { spin: jobs.loadingJobs(), center: true, size: 'xlarge' } --><!-- /ko -->

+ 37 - 8
desktop/core/src/desktop/js/ko/components/ko.jobBrowserLinks.js

@@ -96,7 +96,7 @@ class JobBrowserPanel {
       }
     });
 
-    self.jobCounts = ko.observable({ yarn: 0, schedules: 0 });
+    self.jobCounts = ko.observable({ yarn: 0, schedules: 0, history: 0 });
     self.jobCount = ko.pureComputed(() => {
       let total = 0;
       Object.keys(self.jobCounts()).forEach(value => {
@@ -108,11 +108,13 @@ class JobBrowserPanel {
 
     let lastYarnBrowserRequest = null;
     const checkYarnBrowserStatus = function() {
-      return $.post('/jobbrowser/jobs/', {
-        format: 'json',
-        state: 'running',
-        user: window.LOGGED_USERNAME
-      })
+      return $.post(
+        '/jobbrowser/jobs/',
+        {
+          format: 'json',
+          state: 'running',
+          user: window.LOGGED_USERNAME
+        })
         .done(data => {
           if (data != null && data.jobs != null) {
             huePubSub.publish('jobbrowser.data', data.jobs);
@@ -122,7 +124,8 @@ class JobBrowserPanel {
         })
         .fail(response => {
           console.warn(response);
-        });
+        }
+      );
     };
     let lastScheduleBrowserRequest = undefined;
     const checkScheduleBrowserStatus = function() {
@@ -146,6 +149,30 @@ class JobBrowserPanel {
         }
       );
     };
+    let lastHistoryBrowserRequest = null;
+    const checkHistoryBrowserStatus = function() {
+      return $.post(
+        '/jobbrowser/api/jobs/history',
+        {
+          interface: ko.mapping.toJSON('history'),
+          filters: ko.mapping.toJSON([
+            { states: ['running'] },
+            { text: 'user:' + window.LOGGED_USERNAME },
+            { time: { time_value: 7, time_unit: 'days' } },
+            { pagination: { page: 1, offset: 1, limit: 1 } }
+          ])
+        })
+        .done(data => {
+          if (data != null && data.apps != null) {
+            self.jobCounts()['history'] = data.apps.length;
+            self.jobCounts.valueHasMutated();
+          }
+        })
+        .fail(response => {
+          console.warn(response);
+        }
+      );
+    };
 
     let checkJobBrowserStatusIdx = -1;
     const checkJobBrowserStatus = function() {
@@ -153,9 +180,10 @@ class JobBrowserPanel {
       if (window.ENABLE_QUERY_SCHEDULING) {
         lastScheduleBrowserRequest = checkScheduleBrowserStatus();
       }
+      lastHistoryBrowserRequest = checkHistoryBrowserStatus();
 
       $.when
-        .apply($, [lastYarnBrowserRequest, lastScheduleBrowserRequest])
+        .apply($, [lastYarnBrowserRequest, lastScheduleBrowserRequest, lastHistoryBrowserRequest])
         .done(() => {
           window.clearTimeout(checkJobBrowserStatusIdx);
           checkJobBrowserStatusIdx = window.setTimeout(
@@ -188,6 +216,7 @@ class JobBrowserPanel {
 
       huePubSub.subscribe('check.job.browser', checkYarnBrowserStatus);
       huePubSub.subscribe('check.schedules.browser', checkScheduleBrowserStatus);
+      huePubSub.subscribe('check.history.browser', checkHistoryBrowserStatus);
     }
   }
 }

+ 1 - 1
desktop/libs/notebook/src/notebook/api.py

@@ -523,7 +523,7 @@ def _clear_sessions(notebook):
 def _historify(notebook, user):
   query_type = 'query-%(dialect)s' % notebook if ENABLE_CONNECTORS.get() else notebook['type']
   name = notebook['name'] if (notebook['name'] and notebook['name'].strip() != '') else DEFAULT_HISTORY_NAME
-  is_managed = notebook.get('isManaged') == True # Prevents None
+  is_managed = notebook.get('isManaged') == True  # Prevents None
 
   if is_managed and Document2.objects.filter(uuid=notebook['uuid']).exists():
     history_doc = Document2.objects.get(uuid=notebook['uuid'])