/** Small shared wake-up policy, not a daemon. Durable queue timestamps survive * restart; the next host turn resumes them. Timers never keep a CLI alive. */ const timers = new Map>(); /** Backoff timing only. jobPolicy owns failure classification and pausing; * explicit maintenance runs may retry paused sources without discarding them. */ export function retryAt(attempts: number, now = Date.now()): number { return now + Math.min(3600000, 30000 * 2 ** Math.max(0, attempts - 1)); } export function cancelWake(key: string): boolean { const timer = timers.get(key); if (!timer) return false; clearTimeout(timer); timers.delete(key); return true; } export function wakeAt( key: string, at: number, work: () => void, signal?: AbortSignal, ): void { cancelWake(key); if (signal?.aborted) return; const timer = setTimeout( () => { timers.delete(key); if (!signal?.aborted) work(); }, Math.min(2_147_483_647, Math.max(0, at - Date.now())), ); timer.unref?.(); timers.set(key, timer); // The callback checks the signal too; no recurring listener accumulation. }