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_field, 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_field, flavor = :web)
  super(flavor)
  @env_field = env_field
  @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(metric_from(env))
  rescue => ex
    puts "Problem in autoscaling: #{ex.inspect}"
  end

  @app.call(env)
end

#metric_from(env) ⇒ Object



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

def metric_from(env)
  (Integer(env[@env_field]) rescue 0).tap{|val|
    puts "#{@env_field} => #{env[@env_field]} : #{val}"
  }
end