Class: LogrageWaittime::RequestQueuing

Inherits:
Object
  • Object
show all
Defined in:
lib/lograge_waittime/request_queuing.rb

Constant Summary collapse

REQUEST_START_HEADER =
"HTTP_X_REQUEST_START"
EARLIEST_REQUEST_DATE =
Time.new(2000)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, request_started_at = Time.zone.now.to_f) ⇒ RequestQueuing

Returns a new instance of RequestQueuing.



10
11
12
13
14
# File 'lib/lograge_waittime/request_queuing.rb', line 10

def initialize(env, request_started_at = Time.zone.now.to_f)
  @request_queued_raw = request_start_header(env)
  @request_started_at = request_started_at
  @queued_ms = calculate_queued_ms
end

Instance Attribute Details

#queued_msObject (readonly)

How long was the request queued for, in milliseconds



4
5
6
# File 'lib/lograge_waittime/request_queuing.rb', line 4

def queued_ms
  @queued_ms
end

#request_queued_rawObject (readonly)

Returns the value of attribute request_queued_raw.



5
6
7
# File 'lib/lograge_waittime/request_queuing.rb', line 5

def request_queued_raw
  @request_queued_raw
end

#request_started_atObject (readonly)

Returns the value of attribute request_started_at.



5
6
7
# File 'lib/lograge_waittime/request_queuing.rb', line 5

def request_started_at
  @request_started_at
end

Instance Method Details

#request_queued_atObject



16
17
18
19
20
21
22
# File 'lib/lograge_waittime/request_queuing.rb', line 16

def request_queued_at
  return if request_queued_float.blank?
  @request_queued_at ||= [1000, 1].each do |divisor|
    adjusted = Time.zone.at(request_queued_float / divisor)
    return adjusted if adjusted > EARLIEST_REQUEST_DATE
  end
end