Spaces:
Running
on
T4
Running
on
T4
File size: 910 Bytes
fa1717e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/**
* Shared retry configuration for cold-start handling.
*
* HuggingFace Spaces containers can take 30-60 seconds to wake from sleep.
* This module provides shared constants and utilities for exponential backoff retry.
*/
// Cold start retry configuration
export const MAX_COLD_START_RETRIES = 5;
export const INITIAL_RETRY_DELAY = 2000; // 2 seconds
export const MAX_RETRY_DELAY = 30000; // 30 seconds
/**
* Calculate exponential backoff delay with capped maximum.
*
* @param attempt - Current retry attempt (1-indexed)
* @returns Delay in milliseconds
*/
export function getRetryDelay(attempt: number): number {
return Math.min(INITIAL_RETRY_DELAY * Math.pow(2, attempt - 1), MAX_RETRY_DELAY);
}
/**
* Sleep utility for async delays.
*
* @param ms - Milliseconds to sleep
*/
export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
|