- Progress Update

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-01-26 12:57:06 -05:00
parent b0f4ad7e4f
commit 89224e871c
6 changed files with 425 additions and 64 deletions

View File

@@ -5,7 +5,18 @@ const durationToHumanReadable = require("../utils/durationToHumanReadable");
const calculateStatusDuration = require("../utils/calculateStatusDuration");
const jobLifecycle = async (req, res) => {
const {jobids} = req.body;
// Grab the jobids and statuses from the request body
const {
jobids,
statuses
} = req.body;
if (!jobids) {
return res.status(400).json({
error: "Missing jobids"
});
}
const jobIDs = _.isArray(jobids) ? jobids : [jobids];
const client = req.userGraphQLClient;
@@ -45,7 +56,7 @@ const jobLifecycle = async (req, res) => {
groupedTransitions[jobId] = {
lifecycle: lifecycle,
durations: calculateStatusDuration(lifecycle)
durations: calculateStatusDuration(lifecycle, statuses),
};
}

View File

@@ -11,7 +11,7 @@ const getColor = (key) => {
return '#' + (num % 16777215).toString(16).padStart(6, '0');
};
const calculateStatusDuration = (transitions) => {
const calculateStatusDuration = (transitions, statuses) => {
let statusDuration = {};
let totalDuration = 0;
let summations = [];
@@ -64,14 +64,24 @@ const calculateStatusDuration = (transitions) => {
for (let [status, {value, humanReadable}] of Object.entries(statusDuration)) {
if (status !== 'total') {
summations.push({status, value, humanReadable, percentage: statusDuration[status].percentage, color: getColor(status), roundedPercentage: `${Math.round(statusDuration[status].percentage)}%`});
summations.push({
status,
value,
humanReadable,
percentage: statusDuration[status].percentage,
color: getColor(status),
roundedPercentage: `${Math.round(statusDuration[status].percentage)}%`
});
}
}
const humanReadableTotal = durationToHumanReadable(moment.duration(totalDuration));
return {
summations: _.orderBy(summations, ['value'], ['asc']),
summations: _.isArray(statuses) && !_.isEmpty(statuses) ? summations.sort((a, b) => {
return statuses.indexOf(a.status) - statuses.indexOf(b.status);
}) : summations,
totalStatuses: summations.length,
total: totalDuration,
humanReadableTotal