Class: Mongoid::Railties::ControllerRuntime::Collector
- Inherits:
-
Object
- Object
- Mongoid::Railties::ControllerRuntime::Collector
- 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 collapse
- VARIABLE_NAME =
'Mongoid.controller_runtime'
Class Method Summary collapse
-
.reset_runtime ⇒ Integer
Reset the runtime value to zero the current thread.
-
.runtime ⇒ Integer
Get the runtime value on the current thread.
-
.runtime=(value) ⇒ Integer
Set the runtime value on the current thread.
Instance Method Summary collapse
-
#_completed(e) ⇒ Integer
(also: #succeeded, #failed)
Call when event completed.
-
#started(_) ⇒ nil
Call when event started.
Class Method Details
.reset_runtime ⇒ Integer
Reset the runtime value to zero the current thread.
92 93 94 95 96 |
# File 'lib/mongoid/railties/controller_runtime.rb', line 92 def self.reset_runtime to_now = runtime self.runtime = 0 to_now end |
.runtime ⇒ Integer
Get the runtime value on the current thread.
76 77 78 |
# File 'lib/mongoid/railties/controller_runtime.rb', line 76 def self.runtime Threaded.get(VARIABLE_NAME) { 0 } end |
.runtime=(value) ⇒ Integer
Set the runtime value on the current thread.
85 86 87 |
# File 'lib/mongoid/railties/controller_runtime.rb', line 85 def self.runtime=(value) Threaded.set(VARIABLE_NAME, value) end |
Instance Method Details
#_completed(e) ⇒ Integer Also known as: succeeded, failed
Call when event completed. Updates the runtime value.
67 68 69 |
# File 'lib/mongoid/railties/controller_runtime.rb', line 67 def _completed(e) Collector.runtime += e.duration * 1000 end |
#started(_) ⇒ nil
Call when event started. Does nothing.
60 |
# File 'lib/mongoid/railties/controller_runtime.rb', line 60 def started(_); end |