unrip/src/core/history-writer-refresh-policy.mjs
philipp d151db1e91
Some checks failed
deploy / deploy (push) Failing after 31s
Let history writer catch up through stale backlog
Proof: npm test (140 passing); npm run operator-dashboard:build; git diff --cached --check.

Assumptions: Events older than HISTORY_WRITER_DERIVED_REFRESH_MAX_EVENT_AGE_MS are replay/backfill work; writing them remains required, but expensive derived portfolio/outcome refreshes can wait until the writer reaches fresh events.

Still fake: This does not move or migrate BTC assets; it only improves durable catch-up so fresh inventory can reach request preflight.
2026-05-07 16:13:21 +02:00

15 lines
439 B
JavaScript

export function shouldRunDerivedRefreshForEvent({
event,
now = new Date().toISOString(),
maxEventAgeMs,
} = {}) {
const maxAge = Number(maxEventAgeMs);
if (!Number.isFinite(maxAge) || maxAge < 0) return true;
const eventAt = event?.ingested_at || event?.observed_at || null;
if (!eventAt) return true;
const age = Date.parse(now) - Date.parse(eventAt);
if (!Number.isFinite(age)) return true;
return age <= maxAge;
}