Class: Berater::Middleware::LoadShedder

Inherits:
Object
  • Object
show all
Defined in:
lib/berater/middleware/load_shedder.rb

Constant Summary collapse

PRIORITY_RANGE =
1..5

Instance Method Summary collapse

Constructor Details

#initialize(default_priority: nil) ⇒ LoadShedder

Returns a new instance of LoadShedder.



6
7
8
# File 'lib/berater/middleware/load_shedder.rb', line 6

def initialize(default_priority: nil)
  @default_priority = default_priority
end

Instance Method Details

#call(*args, **opts) {|args, opts| ... } ⇒ Object

Yields:

  • (args, opts)


10
11
12
13
14
15
16
# File 'lib/berater/middleware/load_shedder.rb', line 10

def call(*args, **opts)
  if priority = opts.delete(:priority) || @default_priority
    opts[:capacity] = adjust_capacity(opts[:capacity], priority)
  end

  yield *args, **opts
end