kaikai_test/src/retryQueue.js
2026-05-14 18:53:53 +08:00

40 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}