Home / Function/ withRetry() — supabase Function Reference

withRetry() — supabase Function Reference

Architecture documentation for the withRetry() function in generate-embeddings.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  999b9bcb_cbf3_994c_468b_34a61e74d416["withRetry()"]
  b6da1e2f_3534_5430_6fdb_1a60bda504b3["processEmbeddingBatch()"]
  b6da1e2f_3534_5430_6fdb_1a60bda504b3 -->|calls| 999b9bcb_cbf3_994c_468b_34a61e74d416
  6e840ab5_8116_4027_1a88_735f8e359283["insertSectionBatch()"]
  6e840ab5_8116_4027_1a88_735f8e359283 -->|calls| 999b9bcb_cbf3_994c_468b_34a61e74d416
  b2e63f56_abf5_e0ab_c5a4_eff3e24b6d44["exponentialBackoff()"]
  999b9bcb_cbf3_994c_468b_34a61e74d416 -->|calls| b2e63f56_abf5_e0ab_c5a4_eff3e24b6d44
  80a62cf8_e386_06b3_845e_12f65555becb["delay()"]
  999b9bcb_cbf3_994c_468b_34a61e74d416 -->|calls| 80a62cf8_e386_06b3_845e_12f65555becb
  style 999b9bcb_cbf3_994c_468b_34a61e74d416 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/docs/scripts/search/generate-embeddings.ts lines 53–89

async function withRetry<T>(
  operation: () => Promise<T>,
  maxRetries: number,
  baseDelay: number,
  operationName: string,
  shouldRetryOnError: (error: unknown) => boolean = () => true
): Promise<T> {
  let lastError: Error

  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    try {
      return await operation()
    } catch (error) {
      lastError = error as Error

      // Allow caller to prevent redundant retries for specific errors
      if (!shouldRetryOnError?.(error)) {
        console.warn(`${operationName} encountered non-retryable error:`, lastError.message)
        throw lastError
      }

      if (attempt === maxRetries) {
        console.error(`${operationName} failed after ${maxRetries + 1} attempts:`, lastError)
        throw lastError
      }

      const delayMs = exponentialBackoff(attempt, baseDelay)
      console.warn(
        `${operationName} attempt ${attempt + 1} failed, retrying in ${delayMs}ms:`,
        lastError.message
      )
      await delay(delayMs)
    }
  }

  throw lastError!
}

Subdomains

Frequently Asked Questions

What does withRetry() do?
withRetry() is a function in the supabase codebase.
What does withRetry() call?
withRetry() calls 2 function(s): delay, exponentialBackoff.
What calls withRetry()?
withRetry() is called by 2 function(s): insertSectionBatch, processEmbeddingBatch.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free