class Mongoid::Railties::ControllerRuntime::Collector

The Collector of MongoDB runtime metric, that subscribes to Mongo driver command monitoring. Stores the value within a thread-local variable to provide correct accounting when an application issues MongoDB operations from background threads.

Constants

VARIABLE_NAME

Public Class Methods

reset_runtime() click to toggle source

Reset the runtime value to zero the current thread.

@return [ Integer ] The previous runtime value.

# File lib/mongoid/railties/controller_runtime.rb, line 96
def self.reset_runtime
  to_now = runtime
  self.runtime = 0
  to_now
end
runtime() click to toggle source

Get the runtime value on the current thread.

@return [ Integer ] The runtime value.

# File lib/mongoid/railties/controller_runtime.rb, line 80
def self.runtime
  Threaded.get(VARIABLE_NAME) { 0 }
end
runtime=(value) click to toggle source

Set the runtime value on the current thread.

@param [ Integer ] value The runtime value.

@return [ Integer ] The runtime value.

# File lib/mongoid/railties/controller_runtime.rb, line 89
def self.runtime= value
  Threaded.set(VARIABLE_NAME, value)
end

Public Instance Methods

_completed(e) click to toggle source

Call when event completed. Updates the runtime value.

@param [ Mongo::Event::Base ] e The monitoring event.

@return [ Integer ] The current runtime value.

# File lib/mongoid/railties/controller_runtime.rb, line 71
def _completed e
  Collector.runtime += e.duration * 1000
end
Also aliased as: succeeded, failed
failed(e)
Alias for: _completed
started(_;) click to toggle source

Call when event started. Does nothing.

@return [ nil ] Nil.

# File lib/mongoid/railties/controller_runtime.rb, line 64
def started _; end
succeeded(e)
Alias for: _completed