瀏覽代碼

[jb] Avoid javascript error when application does not have a valid time

In particular having a non numeric for startedTime will create a
TypeError: Cannot read property '1' of null
Romain Rigaux 10 年之前
父節點
當前提交
2e243c6801
共有 2 個文件被更改,包括 6 次插入6 次删除
  1. 4 4
      apps/jobbrowser/src/jobbrowser/views.py
  2. 2 2
      apps/jobbrowser/src/jobbrowser/yarn_models.py

+ 4 - 4
apps/jobbrowser/src/jobbrowser/views.py

@@ -159,14 +159,14 @@ def massage_job_for_json(job, request):
     'finishedReduces': job.finishedReduces,
     'reducesPercentComplete': int(job.reduces_percent_complete) if job.reduces_percent_complete else '',
     'jobFile': hasattr(job, 'jobFile') and job.jobFile or '',
-    'launchTimeMs': hasattr(job, 'launchTimeMs') and job.launchTimeMs or '',
+    'launchTimeMs': hasattr(job, 'launchTimeMs') and job.launchTimeMs or 0,
     'launchTimeFormatted': hasattr(job, 'launchTimeFormatted') and job.launchTimeFormatted or '',
-    'startTimeMs': hasattr(job, 'startTimeMs') and job.startTimeMs or '',
+    'startTimeMs': hasattr(job, 'startTimeMs') and job.startTimeMs or 0,
     'startTimeFormatted': hasattr(job, 'startTimeFormatted') and job.startTimeFormatted or '',
-    'finishTimeMs': hasattr(job, 'finishTimeMs') and job.finishTimeMs or '',
+    'finishTimeMs': hasattr(job, 'finishTimeMs') and job.finishTimeMs or 0,
     'finishTimeFormatted': hasattr(job, 'finishTimeFormatted') and job.finishTimeFormatted or '',
     'durationFormatted': hasattr(job, 'durationFormatted') and job.durationFormatted or '',
-    'durationMs': hasattr(job, 'durationInMillis') and job.durationInMillis or '',
+    'durationMs': hasattr(job, 'durationInMillis') and job.durationInMillis or 0,
     'canKill': can_kill_job(job, request.user),
     'killUrl': job.jobId and reverse('jobbrowser.views.kill_job', kwargs={'job': job.jobId}) or ''
   }

+ 2 - 2
apps/jobbrowser/src/jobbrowser/yarn_models.py

@@ -66,8 +66,8 @@ class Application(object):
       finishTime = self.finishedTime
     setattr(self, 'durationInMillis', finishTime - self.startedTime)
     setattr(self, 'startTimeMs', self.startedTime)
-    setattr(self, 'startTimeFormatted',  format_unixtime_ms(self.startedTime))
-    setattr(self, 'finishTimeFormatted',  format_unixtime_ms(finishTime))
+    setattr(self, 'startTimeFormatted', format_unixtime_ms(self.startedTime))
+    setattr(self, 'finishTimeFormatted', format_unixtime_ms(finishTime))
     setattr(self, 'finishedMaps', None)
     setattr(self, 'desiredMaps', None)
     setattr(self, 'finishedReduces', None)