From a14b2340b0647e1bdf7d3802dc8adffd21d7ab85 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Fri, 8 Nov 2024 09:24:58 -0800 Subject: [PATCH] IO-3017 Lifecycle NaN prevention Signed-off-by: Allan Carr --- server/job/job-lifecycle.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/job/job-lifecycle.js b/server/job/job-lifecycle.js index feb093d6e..ddd58a834 100644 --- a/server/job/job-lifecycle.js +++ b/server/job/job-lifecycle.js @@ -78,10 +78,10 @@ const jobLifecycle = async (req, res) => { Object.keys(flatGroupedAllDurations).forEach((status) => { const value = flatGroupedAllDurations[status].reduce((acc, curr) => acc + curr.value, 0); const humanReadable = durationToHumanReadable(moment.duration(value)); - const percentage = (value / finalTotal) * 100; + const percentage = finalTotal > 0 ? (value / finalTotal) * 100 : 0; const color = getLifecycleStatusColor(status); const roundedPercentage = `${Math.round(percentage)}%`; - const averageValue = value / jobIDs.length; + const averageValue = _size(jobIDs) > 0 ? value / jobIDs.length : 0; const averageHumanReadable = durationToHumanReadable(moment.duration(averageValue)); finalSummations.push({ status, @@ -105,8 +105,11 @@ const jobLifecycle = async (req, res) => { total: finalTotal, statusCounts: finalStatusCounts, humanReadable: durationToHumanReadable(moment.duration(finalTotal)), - averageValue: finalTotal / jobIDs.length, - averageHumanReadable: durationToHumanReadable(moment.duration(finalTotal / jobIDs.length)) + averageValue: _size(jobIDs) > 0 ? finalTotal / jobIDs.length : 0, + averageHumanReadable: + _size(jobIDs) > 0 + ? durationToHumanReadable(moment.duration(finalTotal / jobIDs.length)) + : durationToHumanReadable(moment.duration(0)) } }); };