Class: Rack::Profilers::Stathat

Inherits:
RequestProfiler show all
Defined in:
lib/rack/profilers/stathat.rb

Overview

NOTE: This middleware expects that you are running an EventMachine reactor in the current process, and should not be used otherwise.

Constant Summary

Constants inherited from RequestProfiler

RequestProfiler::VERSION

Instance Method Summary collapse

Methods inherited from RequestProfiler

#call, #run_time, #start_time, #start_time=

Constructor Details

#initialize(app, opts = {}) ⇒ Stathat

Returns a new instance of Stathat.

Parameters:

  • opts (Hash) (defaults to: {})
  • [Proc] (Hash)

    a customizable set of options



14
15
16
# File 'lib/rack/profilers/stathat.rb', line 14

def initialize(app, opts = {})
  @app, @opts = app, opts
end

Instance Method Details

#handle_results(env, request) ⇒ Object

Parameters:

  • env (Hash)

    the rack env

  • request (Rack::Request)

    a request object constructed from env



21
22
23
24
25
26
27
28
29
# File 'lib/rack/profilers/stathat.rb', line 21

def handle_results(env, request)
  clean_url = Utils::UrlStripper.replace_id(request.path)

  EM.next_tick do
    deferrable = EM::StatHat.new.ez_value("#{request.request_method} #{clean_url}", run_time)
    deferrable.callback(&@opts[:callback]) if @opts[:callback]
    deferrable.errback(&@opts[:errback]) if @opts[:errback]
  end
end