40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { PLATFORMS } from "./sites.js";
|
||
|
||
export const retryableStatuses = new Set(["no_match", "no_metric", "blocked", "error"]);
|
||
|
||
export function pendingRetryItems(history) {
|
||
const items = [];
|
||
for (const program of Object.values(history?.programs || {})) {
|
||
const platforms = [];
|
||
const reasons = [];
|
||
|
||
for (const platform of PLATFORMS) {
|
||
const latest = latestPlatformValue(program, platform.id);
|
||
if (!latest || !retryableStatuses.has(String(latest.status || ""))) continue;
|
||
platforms.push(platform.id);
|
||
reasons.push(`${platform.label}:${latest.status}`);
|
||
}
|
||
|
||
if (platforms.length > 0) {
|
||
items.push({
|
||
name: program.name || "",
|
||
platforms,
|
||
reason: reasons.join(";"),
|
||
});
|
||
}
|
||
}
|
||
|
||
return items
|
||
.filter((item) => item.name)
|
||
.sort((a, b) => a.name.localeCompare(b.name, "zh-Hans-CN"));
|
||
}
|
||
|
||
function latestPlatformValue(program, platformId) {
|
||
const values = program?.platforms?.[platformId]?.values || {};
|
||
const runs = [...(program?.runs || [])].reverse();
|
||
for (const run of runs) {
|
||
if (values[run]) return values[run];
|
||
}
|
||
return null;
|
||
}
|