From fa95afbeb337af06b00b6fa01c814a03600a2af9 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Fri, 27 Dec 2024 23:56:52 +0100 Subject: [PATCH 1/2] Remove old check for "too old date" This is always true for last ~4 years. --- www/js/status.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/www/js/status.js b/www/js/status.js index e3dfaee..db4941e 100644 --- a/www/js/status.js +++ b/www/js/status.js @@ -89,19 +89,10 @@ const updateTimeData = fetchMetrics('query', { )) .then(aggregateByChannel); -var earliestStart = moment.utc("2019-12-30T01:00:00Z"); -var idealStart = moment.utc().subtract(30, "days"); -var start; -if (idealStart > earliestStart) { - start = idealStart; -} else { - start = earliestStart; -} -var end = moment.utc().format(); const jobsetData = fetchMetrics('query_range', { query: 'hydra_job_failed', - start: start.format(), - end, + start: moment.utc().subtract(30, "days").format(), + end: moment.utc().format(), step: '1h' }) .then(records => ( From d08d85a9e5e4387ea420169626721d6bb14b00e3 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Sat, 28 Dec 2024 00:22:02 +0100 Subject: [PATCH 2/2] Fetch commit date instead of last eval time --- www/js/status.js | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/www/js/status.js b/www/js/status.js index db4941e..5de223b 100644 --- a/www/js/status.js +++ b/www/js/status.js @@ -54,6 +54,21 @@ async function fetchMetrics(queryType, queryArgs = {}) { return data.result; } +async function fetchCommitDate(commit) { + const response = await fetch(`https://api.github.com/repos/NixOS/nixpkgs/commits/${commit}`); + const data = await response.json(); + return moment.utc(data.commit.author.date); +} + +function fetchAllCommits(revisions) { + let promises = {}; + for (let i = 0; i < revisions.length; i++) { + const revision = revisions[i]; + promises[revision] = (fetchCommitDate(revision)) + }; + return promises; +} + const revisionData = fetchMetrics('query', { query: 'channel_revision' }) @@ -147,8 +162,19 @@ function cmp_channels(left, right) { } init - .then(() => Promise.all([revisionData, updateTimeData, jobsetData])) - .then(([revisions, update_times, jobsets]) => { + .then(() => Promise.all([revisionData, jobsetData])) + .then(async ([revisions, jobsets]) => { + const all_commits = Object.values(revisions).map((v) => v.revision); + + const commit_dates_promises = fetchAllCommits(all_commits); + const commit_dates_entries = await Promise.all( + Object.entries(commit_dates_promises).map(async ([key, promise]) => [key, await promise]) + ); + const commit_dates = Object.fromEntries(commit_dates_entries); + + return [revisions, commit_dates, jobsets]; + }) + .then(([revisions, commit_dates, jobsets]) => { var combined = []; for (let [channel, jobset] of Object.entries(jobsets)) { @@ -164,15 +190,16 @@ init } else { continue } - if (update_times[channel] != undefined) { - var m = moment.unix(update_times[channel]['update_time']); - jobset['update_time_relative'] = m.fromNow() - jobset['update_time_local'] = m.format() + + const commit_date = commit_dates[revisions[channel]['revision']]; + if (commit_date != undefined) { + jobset['update_time_relative'] = commit_date.fromNow() + jobset['update_time_local'] = commit_date.format() // do not use color indications on outdated channels if (jobset['current']) { - if (m > moment().subtract(3, 'days')) { + if (commit_date > moment().subtract(3, 'days')) { jobset['update_age'] = "success"; - } else if (m > moment().subtract(10, 'days')) { + } else if (commit_date > moment().subtract(10, 'days')) { jobset['update_age'] = "warning"; } else { jobset['update_age'] = "important";