Class: Wurk::Processor::Counter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeCounter

Returns a new instance of Counter.



84
85
86
87
# File 'lib/wurk/processor.rb', line 84

def initialize
  @value = 0
  @lock = ::Mutex.new
end

Instance Method Details

#incr(amount = 1) ⇒ Object



89
90
91
# File 'lib/wurk/processor.rb', line 89

def incr(amount = 1)
  @lock.synchronize { @value += amount }
end

#resetObject



93
94
95
96
97
98
99
# File 'lib/wurk/processor.rb', line 93

def reset
  @lock.synchronize do
    val = @value
    @value = 0
    val
  end
end