Expose persistent collection gaps and public Congress links
Retain bill and attachment failure reasons and derive retry counts from saved cursors. Show gap details and retry exhaustion in the collection console while preserving historical records and retry limits. Convert Congress API bill links to public pages and cover diagnostics, mixed dated versions, persistent counts and legacy records with regression tests.
This commit is contained in:
1 parent
dcad5b76a8
commit
d5d350b7ec
8 files changed
+182
-14
No files matched your search
@@ -15,7 +15,41 @@ export function sourceStatus(source: SourceInfo, restarting = false, now = Date.
|
||||
return { type: "primary", text: "采集中" } as const
|
||||
if (source.consecutive_failures)
|
||||
return { type: "danger", text: "失败待重试" } as const
|
||||
if (source.collection_stats?.document_gaps)
|
||||
return { type: "warning", text: "存在文档缺口" } as const
|
||||
if (source.collection_stats?.document_gaps || source.collection_stats?.attachment_gaps || source.collection_stats?.unresolved_bills)
|
||||
return { type: "warning", text: "存在采集缺口" } as const
|
||||
return { type: "info", text: "等待调度" } as const
|
||||
}
|
||||
|
||||
function originalUrl(url: string) {
|
||||
const bill = /^https:\/\/api\.congress\.gov\/v3\/bill\/(\d+)\/([a-z]+)\/(\d+)\/?(?:\?[^#]*)?(?:#.*)?$/i.exec(url)
|
||||
const billTypes: Record<string, string> = {
|
||||
hr: "house-bill",
|
||||
s: "senate-bill",
|
||||
hjres: "house-joint-resolution",
|
||||
sjres: "senate-joint-resolution",
|
||||
hconres: "house-concurrent-resolution",
|
||||
sconres: "senate-concurrent-resolution",
|
||||
hres: "house-resolution",
|
||||
sres: "senate-resolution"
|
||||
}
|
||||
if (bill && billTypes[bill[2].toLowerCase()])
|
||||
return `https://www.congress.gov/bill/${bill[1]}th-congress/${billTypes[bill[2].toLowerCase()]}/${bill[3]}`
|
||||
return url
|
||||
}
|
||||
|
||||
export function collectionGaps(source: Pick<SourceInfo, "history_cursor">) {
|
||||
const groups = [
|
||||
["document_retries", "正文"],
|
||||
["attachment_retries", "附件"],
|
||||
["bill_retries", "法案"]
|
||||
] as const
|
||||
return groups.flatMap(([key, label]) => Object.entries(source.history_cursor?.[key] ?? {}).map(([url, retry]) => ({
|
||||
key: `${key}:${url}`,
|
||||
label,
|
||||
url: originalUrl(retry.document.canonical ?? retry.document.url),
|
||||
error: retry.error || "历史记录未保存具体原因,请核对原文",
|
||||
attempts: retry.attempts,
|
||||
exhausted: retry.attempts >= 3,
|
||||
nextAt: new Date(retry.next_at * 1000).toISOString()
|
||||
})))
|
||||
}
|
||||
Reference in new issue
Block a user