Keep retrying lookups until the sources answer

A network error, timeout, 5xx or 429 no longer ends a lookup or sends a
book to Needs attention. Lookups back off exponentially with jitter (2 s
doubling to 5 min, honouring Retry-After) for as long as the book is
pending, keep each definitive answer so a retry only asks for what is
missing, and limit requests to two at a time per host. Once a call number
is in hand, a step that still fails after six tries is left for the
backfills. Books an earlier version failed for a temporary reason are
queued again at startup.

The cards show which source is not answering and when the next try is,
title search waits for Open Library with a Cancel button, and Look up
again sits next to Fix.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-22 11:35:37 -07:00
1 parent ee10e00ccd
commit e65b10c0fb
24 files changed
+700 -104

No files matched your search

+8 -3
View File
@@ -24,10 +24,15 @@ function trackPending(action: BookAction): void {
const created = Date.parse(b.createdAt);
pendingSince.set(b.id, fromServerTime && Number.isFinite(created) ? Math.min(created, Date.now()) : Date.now());
};
if (action.type === 'upsert') note(action.book, false);
else if (action.type === 'replace') { pendingSince.clear(); action.books.forEach(b => note(b, true)); }
else pendingSince.delete(action.id);
const now = Date.now();
if (action.type === 'upsert') { receivedAt.set(action.book.id, now); note(action.book, false); }
else if (action.type === 'replace') { pendingSince.clear(); receivedAt.clear(); action.books.forEach(b => { receivedAt.set(b.id, now); note(b, true); }); }
else { pendingSince.delete(action.id); receivedAt.delete(action.id); }
}
/** When the page last received each book, so a retry's remaining wait can be counted down locally. */
const receivedAt = new Map<number, number>();
export function retryReceivedAt(book: Book): number { return receivedAt.get(book.id) ?? Date.now(); }
export function lookupStartedAt(book: Book): number { return pendingSince.get(book.id) ?? Date.now(); }
/** Re-renders once a second while `active`, and returns the current time. */