Class: Expeditor::RollingNumber
- Inherits:
-
Object
- Object
- Expeditor::RollingNumber
- Defined in:
- lib/expeditor/rolling_number.rb
Overview
A RollingNumber holds some Status objects and it rolls statuses each ‘per_time` (default is 1 second). This is done so that the statistics are recorded gradually with short time interval rahter than reset all the record every wide time range (default is 10 seconds).
Instance Method Summary collapse
-
#current ⇒ Object
deprecated
Deprecated.
Don’t use, use ‘#total` instead.
- #increment(type) ⇒ Object
-
#initialize(size:, per_time:) ⇒ RollingNumber
constructor
A new instance of RollingNumber.
-
#total ⇒ Expeditor::Status
Newly created status.
Constructor Details
#initialize(size:, per_time:) ⇒ RollingNumber
Returns a new instance of RollingNumber.
10 11 12 13 14 15 16 17 |
# File 'lib/expeditor/rolling_number.rb', line 10 def initialize(size:, per_time:) @mutex = Mutex.new @ring = RingBuffer.new(size) do Expeditor::Status.new end @per_time = per_time @current_start = Time.now end |
Instance Method Details
#current ⇒ Object
Deprecated.
Don’t use, use ‘#total` instead.
36 37 38 39 40 41 42 |
# File 'lib/expeditor/rolling_number.rb', line 36 def current warn 'Expeditor::RollingNumber#current is deprecated. Please use #total instead to fetch correct status object.' @mutex.synchronize do update @ring.current end end |
#increment(type) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/expeditor/rolling_number.rb', line 20 def increment(type) @mutex.synchronize do update @ring.current.increment(type) end end |
#total ⇒ Expeditor::Status
Returns Newly created status.
28 29 30 31 32 33 |
# File 'lib/expeditor/rolling_number.rb', line 28 def total @mutex.synchronize do update @ring.all.inject(Expeditor::Status.new) {|i, s| i.merge!(s) } end end |