Class: OurEelHacks::Rack

Inherits:
Middleware show all
Includes:
Defer::EventMachine
Defined in:
lib/our-eel-hacks/rack.rb

Direct Known Subclasses

ScaleOnRoutingQueue

Instance Method Summary collapse

Methods included from Defer::EventMachine

#trigger_scaling

Constructor Details

#initialize(app, env_fields, flavor = :web) ⇒ Rack

Returns a new instance of Rack.



7
8
9
10
11
# File 'lib/our-eel-hacks/rack.rb', line 7

def initialize(app, env_fields, flavor = :web)
  super(flavor)
  @env_fields = [*env_fields].map(&:to_s)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/our-eel-hacks/rack.rb', line 13

def call(env)
  begin
    autoscale(metrics_from(env))
  rescue => ex
    puts "Problem in autoscaling: #{ex.inspect}"
  end

  @app.call(env)
end

#metrics_from(env) ⇒ Object



23
24
25
26
27
# File 'lib/our-eel-hacks/rack.rb', line 23

def metrics_from(env)
  Hash[ @env_fields.map do |field|
    [field, (Integer(env[field]) rescue 0)]
  end ]
end