Class: Attio::CompositeCircuitBreaker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/attio/circuit_breaker.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Composite circuit breaker for multiple endpoints

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initialize(default_config = {}) ⇒ CompositeCircuitBreaker

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CompositeCircuitBreaker.

Since:

  • 1.0.0



245
246
247
248
249
250
251
252
253
# File 'lib/attio/circuit_breaker.rb', line 245

def initialize(default_config = {})
  @breakers = {}
  @default_config = {
    threshold: 5,
    timeout: 60,
    half_open_requests: 3,
  }.merge(default_config)
  @mutex = Mutex.new
end

Instance Method Details

#call(key) { ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute with circuit breaker for endpoint

Parameters:

  • key (String)

    Endpoint key

Yields:

  • Block to execute

Since:

  • 1.0.0



270
271
272
# File 'lib/attio/circuit_breaker.rb', line 270

def call(key, &block)
  for_endpoint(key).call(&block)
end

#for_endpoint(key, config = {}) ⇒ CircuitBreaker

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get or create circuit breaker for endpoint

Parameters:

  • key (String)

    Endpoint key

  • config (Hash) (defaults to: {})

    Optional config overrides

Returns:

Since:

  • 1.0.0



260
261
262
263
264
# File 'lib/attio/circuit_breaker.rb', line 260

def for_endpoint(key, config = {})
  @mutex.synchronize do
    @breakers[key] ||= CircuitBreaker.new(**@default_config, **config)
  end
end

#reset_all!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reset all circuit breakers

Since:

  • 1.0.0



293
294
295
296
297
# File 'lib/attio/circuit_breaker.rb', line 293

def reset_all!
  @mutex.synchronize do
    @breakers.each_value(&:reset!)
  end
end

#statesHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get all circuit breaker states

Returns:

  • (Hash)

    States by endpoint

Since:

  • 1.0.0



277
278
279
280
281
# File 'lib/attio/circuit_breaker.rb', line 277

def states
  @mutex.synchronize do
    @breakers.transform_values(&:state)
  end
end

#statsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get aggregated statistics

Returns:

  • (Hash)

    Combined statistics

Since:

  • 1.0.0



286
287
288
289
290
# File 'lib/attio/circuit_breaker.rb', line 286

def stats
  @mutex.synchronize do
    @breakers.transform_values(&:stats)
  end
end