Module: ActionController::Instrumentation

Defined in:
lib/time_bandits/monkey_patches/action_controller.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#cleanup_view_runtimeObject

:nodoc:



46
47
48
49
50
51
# File 'lib/time_bandits/monkey_patches/action_controller.rb', line 46

def cleanup_view_runtime #:nodoc:
  consumed_before_rendering = TimeBandits.consumed
  runtime = yield
  consumed_during_rendering = TimeBandits.consumed - consumed_before_rendering
  runtime - consumed_during_rendering
end

#process_action(action, *args) ⇒ Object

patch to ensure that the completed line is always written to the log. this is not necessary anymore with Rails 4 and higher.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/time_bandits/monkey_patches/action_controller.rb', line 9

def process_action(action, *args)
  raw_payload = get_raw_payload
  ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)

  exception = nil
  result = ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
    begin
      super
    rescue Exception => exception
      response.status = 500
      nil
    ensure
      payload[:status] = response.status
      append_info_to_payload(payload)
    end
  end
  raise exception if exception
  result
end

#render(*args) ⇒ Object

patch to ensure that render times are always recorded in the log. this is not necessary anymore with Rails 3 and up.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/time_bandits/monkey_patches/action_controller.rb', line 31

def render(*args)
  render_output = nil
  exception = nil
  self.view_runtime = cleanup_view_runtime do
    Benchmark.ms do
      begin
        render_output = super
      rescue Exception => exception
      end
    end
  end
  raise exception if exception
  render_output
end