mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 05:47:07 +00:00
Add error handling
This commit is contained in:
@@ -2,8 +2,32 @@
|
|||||||
|
|
||||||
const cmp = require('../lib/www/server/lib/comparisons');
|
const cmp = require('../lib/www/server/lib/comparisons');
|
||||||
|
|
||||||
|
async function purgeComparisons () {
|
||||||
|
const groups = await cmp.groups();
|
||||||
|
const comparisons = await cmp.getGroup();
|
||||||
|
|
||||||
|
const pids = new Set(Object.values(groups).flat().map( p => p.pid ));
|
||||||
|
const comparison_pids = new Set(comparisons.map( c => [ c.baseline_pid, c.monitor_pid ] ).flat());
|
||||||
|
|
||||||
|
for (const pid of comparison_pids) {
|
||||||
|
if (!pids.has(pid)) {
|
||||||
|
console.log(`${pid} no longer par of a group. Deleting comparisons`);
|
||||||
|
|
||||||
|
staleComps = comparisons.filter( c => c.baseline_pid == pid || c.monitor_pid == pid );
|
||||||
|
for (c of staleComps) {
|
||||||
|
console.log(`Deleting comparison ${c.baseline_pid} → ${c.monitor_pid}`);
|
||||||
|
await cmp.remove(c.baseline_pid, c.monitor_pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
|
|
||||||
|
console.log("Looking for unreferenced comparisons to purge");
|
||||||
|
await purgeComparisons();
|
||||||
|
|
||||||
console.log("Retrieving project groups");
|
console.log("Retrieving project groups");
|
||||||
const groups = await cmp.groups();
|
const groups = await cmp.groups();
|
||||||
|
|
||||||
@@ -12,7 +36,7 @@ async function main () {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Found ${groups.length} groups: ${Object.keys(groups).join(", ")}`);
|
console.log(`Found ${Object.keys(groups)?.length} groups: ${Object.keys(groups).join(", ")}`);
|
||||||
|
|
||||||
for (const groupName of Object.keys(groups)) {
|
for (const groupName of Object.keys(groups)) {
|
||||||
const projects = groups[groupName];
|
const projects = groups[groupName];
|
||||||
@@ -21,6 +45,11 @@ async function main () {
|
|||||||
|
|
||||||
const comparisons = await cmp.getGroup(groupName);
|
const comparisons = await cmp.getGroup(groupName);
|
||||||
|
|
||||||
|
if (!comparisons || !comparisons.length) {
|
||||||
|
console.log(`No comparisons found for ${groupName}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if there are any projects that have been modified since last comparison
|
// Check if there are any projects that have been modified since last comparison
|
||||||
// or if there are any pairs that are no longer part of the group
|
// or if there are any pairs that are no longer part of the group
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user