Class: Wurk::Processor::Counter
- Inherits:
-
Object
- Object
- Wurk::Processor::Counter
- Defined in:
- lib/wurk/processor.rb
Overview
Thread-safe global counter. Heartbeat reads + resets these every beat to publish per-process stats.
Instance Method Summary collapse
- #incr(amount = 1) ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
123 124 125 126 |
# File 'lib/wurk/processor.rb', line 123 def initialize @value = 0 @lock = ::Mutex.new end |
Instance Method Details
#incr(amount = 1) ⇒ Object
128 129 130 |
# File 'lib/wurk/processor.rb', line 128 def incr(amount = 1) @lock.synchronize { @value += amount } end |
#reset ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/wurk/processor.rb', line 132 def reset @lock.synchronize do val = @value @value = 0 val end end |