Class: Gitlab::RequestContext

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize, Singleton
Defined in:
lib/gitlab/request_context.rb

Constant Summary collapse

RequestDeadlineExceeded =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Attribute Details

#client_ipObject

Returns the value of attribute client_ip


10
11
12
# File 'lib/gitlab/request_context.rb', line 10

def client_ip
  @client_ip
end

#request_start_timeObject

Returns the value of attribute request_start_time


10
11
12
# File 'lib/gitlab/request_context.rb', line 10

def request_start_time
  @request_start_time
end

#start_thread_cpu_timeObject

Returns the value of attribute start_thread_cpu_time


10
11
12
# File 'lib/gitlab/request_context.rb', line 10

def start_thread_cpu_time
  @start_thread_cpu_time
end

Class Method Details

.instanceObject


13
14
15
# File 'lib/gitlab/request_context.rb', line 13

def instance
  Gitlab::SafeRequestStore[:request_context] ||= new
end

Instance Method Details

#ensure_deadline_not_exceeded!Object


26
27
28
29
30
31
32
33
# File 'lib/gitlab/request_context.rb', line 26

def ensure_deadline_not_exceeded!
  return unless enabled?
  return unless request_deadline
  return if Gitlab::Metrics::System.real_time < request_deadline

  raise RequestDeadlineExceeded,
        "Request takes longer than #{max_request_duration_seconds} seconds"
end

#request_deadlineObject


18
19
20
21
22
23
24
# File 'lib/gitlab/request_context.rb', line 18

def request_deadline
  strong_memoize(:request_deadline) do
    next unless request_start_time

    request_start_time + max_request_duration_seconds
  end
end