PhoenixGenApi.WorkerPool.CircuitBreaker (PhoenixGenApi v2.13.0)

Copy Markdown View Source

Shared circuit breaker functions for WorkerPool and Worker.

This module provides common circuit breaker logic to avoid code duplication between the pool-level and worker-level circuit breakers.

Summary

Functions

Checks if the circuit breaker is open (in cooldown period).

Functions

circuit_open?(opened_at, cooldown_ms)

Checks if the circuit breaker is open (in cooldown period).

Returns true if the circuit breaker is open (rejecting requests), false if requests should be allowed.

Parameters

  • circuit_open_at: The monotonic time (in milliseconds) when the circuit was opened, or nil if the circuit is closed.
  • cooldown_ms: The cooldown period in milliseconds.

Examples

iex> CircuitBreaker.circuit_open?(nil, 5000)
false

iex> now = System.monotonic_time(:millisecond)
iex> CircuitBreaker.circuit_open?(now, 5000)
true