From 7fd8bd2e00c9b0519b9a342dfceb330eeea76f9b Mon Sep 17 00:00:00 2001 From: Cameron Dawson Date: Mon, 14 Oct 2019 17:51:01 -0700 Subject: [PATCH] Bug 1581739 - Fix when NaN duration is displayed (#5512) --- treeherder/model/models.py | 3 ++- ui/helpers/job.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/treeherder/model/models.py b/treeherder/model/models.py index 86e89d15f..abf03de97 100644 --- a/treeherder/model/models.py +++ b/treeherder/model/models.py @@ -672,7 +672,8 @@ class Job(models.Model): def get_duration(submit_time, start_time, end_time): endtime = end_time if to_timestamp(end_time) else datetime.datetime.now() starttime = start_time if to_timestamp(start_time) else submit_time - return round((endtime - starttime).total_seconds() / 60) + seconds = max((endtime - starttime).total_seconds(), 60) + return max(round(seconds / 60), 1) class TaskclusterMetadata(models.Model): diff --git a/ui/helpers/job.js b/ui/helpers/job.js index 228f19005..dcd983ee4 100644 --- a/ui/helpers/job.js +++ b/ui/helpers/job.js @@ -176,7 +176,6 @@ export const addAggregateFields = function addAggregateFields(job) { platform, platform_option, signature, - duration, submit_timestamp, start_timestamp, end_timestamp, @@ -199,16 +198,20 @@ export const addAggregateFields = function addAggregateFields(job) { .join(' '); job.searchStr = `${job.title} ${signature}`; - if (!duration) { + if (!('duration' in job)) { // If start time is 0, then duration should be from requesttime to now // If we have starttime and no endtime, then duration should be starttime to now // If we have both starttime and endtime, then duration will be between those two const endtime = end_timestamp || Date.now() / 1000; const starttime = start_timestamp || submit_timestamp; - job.duration = Math.round((endtime - starttime) / 60, 0); + const diff = Math.max(endtime - starttime, 60); + + job.duration = Math.round(diff / 60, 0); } - job.hoverText = `${job_type_name} - ${job.resultStatus} - ${job.duration} mins`; + job.hoverText = `${job_type_name} - ${job.resultStatus} - ${ + job.duration + } min${job.duration > 1 ? 's' : ''}`; return job; };