/** * How long a display waits before trying a failed request again. * * Exponential from one second to a one-minute ceiling, so a screen whose server is restarting is * back within seconds, and one whose server is down for an evening asks once a minute rather than * hammering it. The wait is jittered between half and all of that step, so a building's worth of * screens that lost the server at the same moment do not all come back at the same moment. * * There is no attempt limit. A television on a wall has nobody to press Retry, so giving up is the * one thing it must never do. */ export const DISPLAY_RETRY_BASE_MS = 1_000; export const DISPLAY_RETRY_MAX_MS = 60_000; export function displayRetryDelayMs(attempt: number, random: () => number = Math.random): number { const step = Math.min( DISPLAY_RETRY_MAX_MS, DISPLAY_RETRY_BASE_MS * 2 ** Math.min(Math.max(0, attempt), 16), ); return Math.round(step / 2 + (step / 2) * Math.min(1, Math.max(0, random()))); }