Class: Serf::Middleware::RequestTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/serf/middleware/request_timer.rb

Overview

Middleware to time the execution of the remaining stack, saving the timing into the ‘serf_elapsed_time’ field in the parcel.

Defined Under Namespace

Classes: Timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, *args) ⇒ RequestTimer

Returns a new instance of RequestTimer.



13
14
15
16
17
# File 'lib/serf/middleware/request_timer.rb', line 13

def initialize(app, *args)
  opts = Optser.extract_options! args
  @app = app
  @timer = opts.get :timer, Serf::Middleware::RequestTimer::Timer
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



10
11
12
# File 'lib/serf/middleware/request_timer.rb', line 10

def app
  @app
end

#timerObject (readonly)

Returns the value of attribute timer.



11
12
13
# File 'lib/serf/middleware/request_timer.rb', line 11

def timer
  @timer
end

Instance Method Details

#call(parcel) ⇒ Object



19
20
21
22
23
24
# File 'lib/serf/middleware/request_timer.rb', line 19

def call(parcel)
  t = timer.start
  response_parcel = app.call parcel
  response_parcel[:serf_elapsed_time] = t.mark
  return response_parcel
end