Class: FaradayDynamicTimeout::CapacityStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday_dynamic_timeout/capacity_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(buckets:, redis:, name: nil, threads_per_process: 1) ⇒ CapacityStrategy

Returns a new instance of CapacityStrategy.



5
6
7
8
9
10
# File 'lib/faraday_dynamic_timeout/capacity_strategy.rb', line 5

def initialize(buckets:, redis:, name: nil, threads_per_process: 1)
  @config = buckets
  @redis = redis
  @name = (name || "default").to_s
  @threads_per_process = threads_per_process
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/faraday_dynamic_timeout/capacity_strategy.rb', line 12

def call
  process_count = count_processes
  threads_count = total_threads(process_count)

  buckets_config.collect do |bucket|
    timeout = fetch_indifferent_key(bucket, :timeout)&.to_f
    limit = fetch_indifferent_key(bucket, :limit)&.to_i
    capacity = fetch_indifferent_key(bucket, :capacity)&.to_f
    {timeout: timeout, limit: capacity_limit(capacity, limit, threads_count)}
  end
end