require "faraday"
require "faraday/retry"
module Http
class RetryableError < StandardError; end
class CircuitOpenError < StandardError; end
export type CircuitState = "closed" | "open" | "half-open";
export interface CircuitBreakerOptions {
failureThreshold: number;
resetTimeout: number; // ms to wait in "open" before probing
onStateChange?: (from: CircuitState, to: CircuitState) => void;
package main
import (
"context"
"net/http"
"time"
public class ProductAggregator implements AutoCloseable {
private final RemoteServices services;
private final ExecutorService pool = Executors.newFixedThreadPool(8);
public ProductAggregator(RemoteServices services) {
module BoundedFanOut
Result = Struct.new(:value, :error) do
def ok?
error.nil?
end
end
package httpretry
import (
"math/rand"
"time"
)
import random
from dataclasses import dataclass
from typing import Iterator
@dataclass(frozen=True)
class CircuitBreaker
class CircuitOpenError < StandardError; end
def initialize(name, redis: Redis.current, failure_threshold: 5, failure_window: 60, cooldown: 30)
@key = "circuit:#{name}"
@redis = redis