Class: Mongoid::Railties::ControllerRuntime::Collector
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/mongoid/railties/controller_runtime.rb |
Overview
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.
Constant Summary
-
VARIABLE_NAME =
# File 'lib/mongoid/railties/controller_runtime.rb', line 59"Mongoid.controller_runtime".freeze
Class Attribute Summary
-
.runtime ⇒ Integer
rw
Get the runtime value on the current thread.
-
.runtime=(value) ⇒ Integer
rw
::Set
the runtime value on the current thread.
Class Method Summary
-
.reset_runtime ⇒ Integer
Reset the runtime value to zero the current thread.
Instance Method Summary
-
#_completed(e) ⇒ Integer
(also: #succeeded, #failed)
Call when event completed.
-
#failed(e)
Alias for #_completed.
-
#started(_) ⇒ nil
Call when event started.
-
#succeeded(e)
Alias for #_completed.
Class Attribute Details
.runtime ⇒ Integer (rw)
Get the runtime value on the current thread.
# File 'lib/mongoid/railties/controller_runtime.rb', line 80
def self.runtime Threaded.get(VARIABLE_NAME) { 0 } end
.runtime=(value) ⇒ Integer (rw)
::Set
the runtime value on the current thread.
# File 'lib/mongoid/railties/controller_runtime.rb', line 89
def self.runtime= value Threaded.set(VARIABLE_NAME, value) end
Class Method Details
.reset_runtime ⇒ Integer
Reset the runtime value to zero the current thread.
Instance Method Details
#_completed(e) ⇒ Integer Also known as: #succeeded, #failed
Call when event completed. Updates the runtime value.
# File 'lib/mongoid/railties/controller_runtime.rb', line 71
def _completed e Collector.runtime += e.duration * 1000 end
#failed(e)
Alias for #_completed.
# File 'lib/mongoid/railties/controller_runtime.rb', line 75
alias :failed :_completed
#started(_) ⇒ nil
Call when event started. Does nothing.
# File 'lib/mongoid/railties/controller_runtime.rb', line 64
def started _; end
#succeeded(e)
Alias for #_completed.
# File 'lib/mongoid/railties/controller_runtime.rb', line 74
alias :succeeded :_completed